![](/img/trans.png)
[英]Why does a Java coded HTTP GET deliver a different web page than a seemingly identical Firefox GET request?
[英]Why does response to my Java GET request have fewer headers than the same URL for Curl
我正在使用OANDA API。 該文檔指出,對所有成功的GET請求的響應都將包含一個ETag標頭: http : //developer.oanda.com/rest-live/development-guide/#etag
我已經向Curl請求成功時,就是這種情況:
$ curl -i "https://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD"
HTTP/1.1 200 OK
Server: openresty/1.7.0.1
Date: Fri, 26 Dec 2014 17:27:01 GMT
Content-Type: application/json
Content-Length: 139
Connection: keep-alive
ETag: "6a6e222a3f90df8f333ff2a6edfb603e4a354905"
{
"prices" : [
{
"instrument" : "EUR_USD",
"time" : "2014-12-26T17:26:12.336249Z",
"bid" : 1.24105,
"ask" : 1.24119
}
]
}
但是,當我成功使用HttpClient org.apache.httpcomponents 4.3
請求時,不包括Content-Length和ETag標頭。
2014-12-26 17:27:54 INFO RestClient:91 - Executing request: GET https://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD HTTP/1.1
2014-12-26 17:27:55 INFO RestClient:103 - Response OK, processing...
2014-12-26 17:27:55 INFO RestClient:108 - {
"prices" : [
{
"instrument" : "EUR_USD",
"time" : "2014-12-26T17:28:01.935790Z",
"bid" : 1.241,
"ask" : 1.24117
}
]
}
2014-12-26 17:27:55 INFO RestClient:110 - Headers: [Server: openresty/1.7.0.1, Date: Fri, 26 Dec 2014 17:28:14 GMT, Content-Type: application/json, Transfer-Encoding: chunked, Connection: keep-alive]
當我記錄接收到的所有響應Java GET請求的標頭時,我缺少ETag和Content-Length標頭。
我想在我的Java代碼中使用ETag標頭,所以請您能幫助我理解為什么不返回它的原因。
默認情況下,HttpClient啟用了壓縮,並且啟用壓縮后,OANDA API不支持ETag:
Note: ETags can not be used in conjunction with compressed responses.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.