我正在玩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标头,所以请帮助我理解为什么不返回它。
答案 0 :(得分:1)
默认情况下,HttpClient启用了压缩,并且在启用压缩时OANDA API不支持ETag:
Note: ETags can not be used in conjunction with compressed responses.