我一直在試圖獲取由列舉HTTPMethod發送的頭,使用HttpClient的4,但沒有任何成功...問題顯示請求頭與Apache HttpClient的4
這裏是我的代碼:
HttpClient httpClient = new DefaultHttpClient();
HttpParams httpParams = httpClient.getParams();
HttpGet httpGet = new HttpGet("http://www.google.fr");
HttpResponse response = httpClient.execute(httpGet);
log.info("*** Request headers ***");
Header[] requestHeaders = httpGet.getAllHeaders();
for(Header header : requestHeaders) {
log.info(header.toString());
}
log.info("***********************");
log.info("*** reponse ***");
log.info(response.getStatusLine());
Header[] headers = response.getAllHeaders();
for(Header header : headers) {
log.info(header.toString());
}
但結果是:
00:27:57,368 INFO - *** Request headers ***
00:27:57,368 INFO - ***********************
00:27:57,368 INFO - *** reponse ***
00:27:57,368 INFO - HTTP/1.1 200 OK
00:27:57,368 INFO - Date: Sun, 15 Aug 2010 22:28:09 GMT
00:27:57,368 INFO - Expires: -1
00:27:57,368 INFO - Cache-Control: private, max-age=0
00:27:57,368 INFO - Content-Type: text/html; charset=ISO-8859-1
00:27:57,368 INFO - Set-Cookie:
[..]
阿卡響應報頭是好的,但不是要求的。 (如果我在執行語句之前移動日誌請求頭塊,結果相同)。
(不,我不想只看到他們,所以設置日誌級別調試心不是可以接受的)
任何人都可以幫助嗎?
感謝您的回答,但我說更改日誌級別不可接受:我需要存儲發送的標頭。您確定在執行請求之前甚至之後無法獲取它們? – 2010-08-16 07:57:51