I’m using apache commons httpClient 3.0.1 and by default it sets the user agent to Jakarta Commons-HttpClient/3.0, I know to set a custom value but what I need now its to completly remove the User-Agent header from the request, i know that value comes from DefaultHttpParamsFactory.java
It’s there a way to change the behavior of that factory ? or to specify my own factory
One solution is to subclass the method and override the addUserAgentRequestHeader method. Something like this:
As you noticed, you can only change the user agent value but not remove it entirely by modifying the parameters. This is because the HttpMethodBase class uses
"Jakarta Commons-HttpClient"as the hard-coded default if no user agent value has been provided as a parameter.Note that as mentioned in comments above, switching to the updated HttpClient codebase of the new Apache HttpComponents project would be a good idea going forward.