为什么Http Get不返回If-None-Match?

时间:2015-08-28 03:27:38

标签: java http

我使用curl测试并返回 304 Not Modified

curl -i -H "If-None-Match: \"df3c2a09938aa3c0cfdb945a41a5c2430e3832b6\"" "https://graph.facebook.com/v2.4/me/adaccounts?access_token=******************************"

这是来自服务器的响应:

 HTTP/1.1 304 Not Modified
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=UTF-8
X-FB-Trace-ID: Ef0W7CPfAwo
X-FB-Rev: 1907442
Pragma: no-cache
Cache-Control: private, no-cache, no-store, must-revalidate
Facebook-API-Version: v2.4
Expires: Sat, 01 Jan 2000 00:00:00 GMT
X-FB-Debug: tGY11aw+eMAejPHXFtD4REFwgwzFR6GLrVvwl6f5aeZsVVwq+AGSa2i5TOfk8C7523h+
0S6M3TOTOK94ABIZ4w==
Date: Fri, 28 Aug 2015 03:07:59 GMT
Connection: keep-alive
Content-Length: 0

但在java中我使用下面的代码,但它没有返回 304 Not Modified

    URL sourceURL = new URL("https://graph.facebook.com/v2.4/me/adaccounts?access_token=************************");
    HttpURLConnection sourceConnection = (HttpURLConnection) sourceURL.openConnection();
    sourceConnection.addRequestProperty("If-None-Match", "df3c2a09938aa3c0cfdb945a41a5c2430e3832b6");
    sourceConnection.connect();

这是来自服务器的响应:

null:HTTP/1.1 200 OK
ETag:"df3c2a09938aa3c0cfdb945a41a5c2430e3832b6"
Content-Length:342
Expires:Sat, 01 Jan 2000 00:00:00 GMT
Connection:keep-alive
Cache-Control:private, no-cache, no-store, must-revalidate
Pragma:no-cache
X-FB-Debug:BDqNs5aELmixSyTcDnmFGio4veU494IJh7/mlAxzfVX705e2cmNwtswGYp38XOyfL6gAOS1ZyvAWdl25k0Nx/g==
Access-Control-Allow-Origin:*
Date:Fri, 28 Aug 2015 03:08:49 GMT
Facebook-API-Version:v2.4
X-FB-Trace-ID:C9BsIg/gIFq
Content-Type:application/json; charset=UTF-8
X-FB-Rev:1907442

有人可以告诉我原因吗? 非常感谢。

1 个答案:

答案 0 :(得分:1)

实体标签需要引用:)

response 
   ETag: "df3c2a09938aa3c0cfdb945a41a5c2430e3832b6"

request
   If-None-Match: "df3c2a09938aa3c0cfdb945a41a5c2430e3832b6"

您设置的请求标头未引用:)