View Single Post
  #2 (permalink)  
Old 04-08-2008, 02:42 PM
DonCash's Avatar
DonCash DonCash is offline
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 237
DonCash will become famous soon enoughDonCash will become famous soon enough
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:

Code:
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:

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!
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|| Don't forget to:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote