View Single Post
  #3 (permalink)  
Old 06-20-2008, 03:04 PM
Sarinam Sarinam is offline
Senior Member
 
Join Date: Jun 2008
Posts: 121
Rep Power: 0
Sarinam is on a distinguished road
Default
Originally Posted by DonCash View Post
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("");

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!
i have also face same problem.Some url open in code and some one is not.I cann't understand.Plz help me to solve the problem.If you need code then i will give you..

Thxs in Advance..
Reply With Quote