hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Wertheim ...@hyperreal.org>
Subject upgrading from v3 to v4, setting request headers
Date Wed, 28 Aug 2013 15:55:14 GMT
I'm upgrading from commons-httpclient-3.1 to httpclient-4.2.5
and fluent-hc-4.2.5.

My code is accessing a web services API that requires some arguments be
passed in as http request headers.

The version of my code that uses commons-httpclient-3.1, which definitely
works, is this:
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(urlString);
getMethod.setRequestHeader("search-client-ip", ipAddressString);
getMethod.setRequestHeader("User-Agent", userAgentString);
httpClient.executeMethod(getMethod);
InputStream is = getMethod.getResponseBodyAsStream();

The version of my code that uses httpclient-4.2.5 and fluent-hc-4.2.5 is
this:
Request request = Request.Get(urlString);
request.addHeader("search-client-ip", ipAddressString);
request.addHeader("User-Agent", userAgentString);
InputStream is =
request.execute().returnResponse().getEntity().getContent();

The new version doesn't seem to work as well as the old version.  I haven't
been able to determine exactly what the issue is, other than that
occasionally no data is returned.

If you know both the 3.1 and 4.2.5 APIs pretty well, does the new code look
correct to you?  I'm wondering if I'm missing something obvious.  Does
4.2.5's Request.addHeader behave identically to 3.1's
GetMethod.setRequestHeader?

Thanks,
Mike

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message