Re: Java and robots...

John_R_R_Leavitt@NL.CS.CMU.EDU
Thu, 13 Feb 97 18:38:26 EST


>On Thu, 13 Feb 1997, Manuel J. Kwak wrote:
>
>> Hello!
>> Im coding a Web-robot using Java as implementation language, and I want
>> to send the user-agent field with the info about the robot to the WWW
>> server. But I haven't found an easy way to made it using the URL
>> classes.
>> Anybody knows something about that?
>
>I believe you are correct. Unless I am mistaken, the URL class gives you
>no control of the HTTP request headers. Take a look at the Socket class.
>It looks like that will to a better job (but will obviously involve more
>programming).

The URL class does not, because it is used only for representing URLs.
The URLConnection class, on the other hand, has several methods for
this sort of thing:

static setDefaultRequestProperty
setIfModifiedSince
setRequestProperty

These will let you set whatever headers you want. For example:

conn.setRequestProperty("User-Agent", "MadDog/1.5");

One caveat: The user agent actually sent will look like this:

MadDog/1.5, JavaJDK1.1beta3.3

which is a little annoying.

-John.

John R. R. Leavitt | Director, Advanced Technologies | Lycos Inc
412 208 1033 | jrrl@lycos.com | http://polarbear.eng.lycos.com/jrrl/
with some luck i just might keep on climbing
better to climb than to face any fall
_________________________________________________
This messages was sent by the robots mailing list. To unsubscribe, send mail
to robots-request@webcrawler.com with the word "unsubscribe" in the body.
For more info see http://info.webcrawler.com/mak/projects/robots/robots.html