• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTPClient

 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically my web application is retrieving the client's request to view a web page such as "www.yahoo.com" and ask the server on my web application. Just like a proxy only my application will be doing specific transformations.
In the beginning i was using low-level sockets but it showed that i was basically reinventing the wheel and found that HTTPClient had the flexibility that i needed.
Now i am trying to understand how HTTPClient works.
My question is this:
I need to send the client's request to the server, but i need to send the request as if it came from the client itself, how is this done in HTTPClient?
Do i need to make use of the HttpConnectionManager() method?
If so is it possible to supply an example as i could not find one and i am not understanding how to use it?

Thank you very much for the comments you have been supplying me
 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it
client.getParams().setParameter("http.useragent", "My Browser");
where the "http.useragent" can be found from the User-Agent header value
and what would be the value used for "My Browser" ?

But then what about all the request header's which the client sent?
 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i understood the code:
client.getParams().setParameter("http.useragent", "My Browser");
basically "http.useragent" is the name and "My Browser" would be its value.

But i still need some help on how to change the request in HTTPClient as if it came from the client itself and not from my web application...
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request will never be exactly the same, since it's coming from a different IP address. Some web sites take the IP into account, so it's good to remember that.

Apart from that, the servlet should read all the incoming request headers and use those for the HttpClient request that is sent out.
 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what i want to do, use exactly the same request header. But i dont know how to do it with HTTPClient...
I found out how to change the User-Agent field with HTTPClient by doing:
HTTPClient.getParams().setParameter("http.useragent", "My Browser");
But the other fields i dont know how to do it...
 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: i know how to read the request headers but i dont know how to send them out to the server using HTTPClient, that is my problem.
 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i have found out how:
The class HttpMethodBase has the method public void setRequestHeader(String headerName,String headerValue)
This method sets the specified request header, overwriting any previous value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!