Hello,

I am not sure if this is a bug or I am not running this right.

I am trying to get the preferences architecture to modify the http.useragent
property at the client level, and then retrieve the value at the method and
host level. The value gets percolated down to the Method level but the Host
level value does not change and gives the global value. See code below.

As per the 3.0 B2 documentation, the Method and Host params should try and
retrieve the value of the http.useragent from their local cache, and if it
they do not find it, should go up the heirarchy, till they reach the global
params. Since in the code below, the value is set at the Client level, one
lower than the Global level, it should be retrieved from the Client level
for both Method and Host params.

Regards,
Vikram

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HostConfiguration;

public class HttpClientTest {

 public static void main(String args[]) throws Exception {

  HttpClient client = new HttpClient();
  client.getParams().setParameter("http.useragent", "My Browser");  // set
the value here

  HostConfiguration host = new HostConfiguration();
  host.setHost("www.google.com");

  GetMethod method = new GetMethod("/");

  int returnCode = client.executeMethod(host, method);

  System.err.println("User-Agent: " +
    host.getParams().getParameter("http.useragent"));  // does not print My
Browser

  System.err.println("User-Agent: " +
    method.getParams().getParameter("http.useragent")); // prints My Browser

  method.releaseConnection();
 }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to