Hello asheesh,
Welcome to the Java Forums.
It seems to me this is because the sites are blocking connectings from programs that are not web browsers. What you need to do is to trick these sites into thinking your program is a web browser.
Try this:
import java.net.*;
import java.io.*;
class httpconnect {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.anywebsite.com/");
URLConnection spoof = url.openConnection();
spoof.setRequestProperty(
"User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String strLine = "";
while ((strLine = in.readLine()) != null) {
System.out.println(strLine);
}
in.close();
}
}
Note this bit of code:
spoof.setRequestProperty(
"User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
This is what tricks the sites into thinking you are using a web browser.
I'm sure this will fix your problem!