Hello, I need to build some HTTP utilities. Jakarta HttpClient seemed
to do the job apparently, but I can't find a way to change the
user-agent header!!!
reading the JavaDocs I got as far as:
getmethod = new GetMethod(url_to_get);
Header ua = new Header("User-Agent","Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)");
getmethod.USER_AGENT = ua;
Alas, for reasons I can't understand, this is not permitted:
[javac] DocumentRetriever.java:110: USER_AGENT has protected access in
org.apache.commons.httpclient.HttpMethodBase
[javac] getmethod.USER_AGENT = ua;
[javac] ^
[javac] 1 error
what am I missing?
thanks
luca
Hi,
The error tells it clearly :
the USER_AGENT variable is declared as "protected" in HttpMethodBase
This means that your class can't access it unless it itself extends some
HttpMethodBase class.
Moreover, this variable is declared as "final", which means it can't be
modified.
So USER_AGENT for HTTP Client can't be anything else that what they
specified in the code.
see this part of HttpMethodBase, especially the getProperty :
/** The User-Agent header sent on every request. */
protected static final Header USER_AGENT;
static {
String agent = null;
try {
agent = System.getProperty("httpclient.useragent");
} catch (SecurityException ignore) {
}
if (agent == null) {
agent = "Jakarta Commons-HttpClient/2.0.1";
}
USER_AGENT = new Header("User-Agent", agent);
}
Regards,
Arnaud
> Hello, I need to build some HTTP utilities. Jakarta HttpClient seemed
> to do the job apparently, but I can't find a way to change the
[quoted text clipped - 19 lines]
>
> luca
Juha Laiho - 21 May 2005 19:08 GMT
"Arnaud Berger" <a.bergerNO@SPAMlibertycontact.fr> said:
>> Hello, I need to build some HTTP utilities. Jakarta HttpClient seemed
>> to do the job apparently, but I can't find a way to change the
[quoted text clipped - 9 lines]
>So USER_AGENT for HTTP Client can't be anything else that what they
>specified in the code.
Except by setting the system property httpclient.useragent, as was shown
in the code snippet:
>see this part of HttpMethodBase, especially the getProperty :
>
[quoted text clipped - 12 lines]
> USER_AGENT = new Header("User-Agent", agent);
> }

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)