通过HttpClient获取在响应标头中分块的Transfer-Encoding

时间:2015-12-05 08:43:24

标签: java httpclient chunked-encoding response-headers getmethod

我希望通过此代码

获取响应标头中的位置值
HttpGet getRequest = null;
CloseableHttpResponse response = null;
getRequest = new HttpGet("https://wl-prod.sabresonicweb.com/SSW2010/B3QE/webqtrip.html?searchType=NORMAL&journeySpan=RT&origin=SGN&destination=DAD&departureDate=2016-01-31&returnDate=2016-02-01&numAdults=2&numChildren=0&numInfants=0&alternativeLandingPage=true&promoCode=&lang=vi_VN");
getRequest.setHeader("Host", "wl-prod.sabresonicweb.com");
getRequest.setHeader("User-Agent", defaultUserAgent);
getRequest.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
getRequest.setHeader("Accept-Language", "en-US,en;q=0.5");
getRequest.setHeader("Accept-Encoding", "gzip, deflate");
getRequest.setHeader("Referer", "http://vietnamairlines.com/");
getRequest.setHeader("Connection", "keep-alive");

response = httpClient.execute(getRequest, context);
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
    System.out.println("Key : " + header.getName() 
          + " ,Value : " + header.getValue());
}

然而,我收到的结果是:

密钥:缓存控制,值:无缓存 Key:Expires,Value:Thu,1970年1月1日00:00:00 GMT 键:X-FRAME-OPTIONS,值:SAMEORIGIN 关键词:Pragma,价值:无缓存 密钥:缓存控制,值:无存储 密钥:内容类型,值:text / html; charset = UTF-8 密钥:转移编码,价值:分块 密钥:Vary,Value:Accept-Encoding 关键:日期,价值:周六,05 Dec 2015 08:36:16 GMT 密钥:服务器,价值:

当我使用Fiddler时,我可以像这样得到位置响应标头的值:

HTTP/1.1 302 Found
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
X-FRAME-OPTIONS: SAMEORIGIN
Pragma: no-cache
Cache-Control: no-store
Location: https://wl-prod.sabresonicweb.com/SSW2010/B3QE/webqtrip.html?execution=e2s1
Content-Length: 0
Date: Sat, 05 Dec 2015 08:00:30 GMT
Server: 

如何通过HttpClient Get方法获取响应标头中的位置值?

0 个答案:

没有答案