URL connection -- browser headers

  • Thread starter Manivannan Palanichamy
  • Start date
M

Manivannan Palanichamy

Hi
I am writing a java url connection code to read a web page. The
intelligent web server denies the request (returns 500 error). Yes, I
know the reason -- the web server identifies my java client as a robot/
spam program. Is there any way to pass the browser headers like ,
Accept-Language: en ?
I know I can pass these using java socket, but is there anyway to
put these values in properties for URL connection?
 
A

Andrew Thompson

Manivannan Palanichamy wrote:
...
I am writing a java url connection code to read a web page.
URL?

...The
intelligent web server denies the request (returns 500 error). Yes, I
know the reason -- the web server identifies my java client as a robot/
spam program. Is there any way to pass the browser headers like ,
Accept-Language: en ?

Sure, but why not ..
a) convince the site administrators to allow connections
from UA's that identify themselves as Java, or..
b) respect their wishes *not* to connect?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Manivannan said:
I am writing a java url connection code to read a web page. The
intelligent web server denies the request (returns 500 error). Yes, I
know the reason -- the web server identifies my java client as a robot/
spam program. Is there any way to pass the browser headers like ,
Accept-Language: en ?
I know I can pass these using java socket, but is there anyway to
put these values in properties for URL connection?

URL url = new URL("http://www.foobar.com/");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)");

(this is emulating Windows 2000 and IE 5.0 - you may want something
more recent)

Arne
 
M

Manivannan Palanichamy

URL url = new URL("http://www.foobar.com/");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)");

(this is emulating Windows 2000 and IE 5.0 - you may want something
more recent)

Arne

Cool and quick idea. Haven't tried it. but, thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top