Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > URL connection -- browser headers

Reply
Thread Tools

URL connection -- browser headers

 
 
Manivannan Palanichamy
Guest
Posts: n/a
 
      08-10-2007
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?

--
Manivannan.Palanichamy (@) Oracle.com
http://mani.gw.googlepages.com/index.html

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      08-11-2007
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?

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via http://www.javakb.com

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      08-11-2007
Manivannan Palanichamy wrote:
> 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
 
Reply With Quote
 
Manivannan Palanichamy
Guest
Posts: n/a
 
      08-11-2007
On Aug 11, 7:10 am, Arne Vajh°j <(E-Mail Removed)> wrote:
> Manivannan Palanichamy wrote:
> > 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


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

--
Manivannan.Palanichamy (@) Oracle.com
http://mani.gw.googlepages.com/index.html


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with wsgiref.headers.Headers Phil Python 4 01-17-2010 04:47 PM
Server cannot clear headers after HTTP headers have been sent Ian ASP .Net Security 2 03-20-2007 09:00 AM
URL - substitution of a correct URL by a GUID like URL in favorites. Just D. ASP .Net Mobile 0 08-11-2004 04:26 PM
redirect URL's, return URL's, and URL Parameters Jon paugh ASP .Net 1 07-10-2004 05:29 AM
Reading 'received' headers: Email Headers Parsing dont bother Python 0 03-03-2004 08:18 PM



Advertisments