gpt4 book ai didi

java - HTTP 未返回 304

转载 作者:可可西里 更新时间:2023-11-01 17:05:31 27 4
gpt4 key购买 nike

嘿,我正在尝试构建一个 HTTP 客户端,但我似乎无法弄清楚为什么我没有收到代码“304,未修改”。该文件的最后修改日期是 2007 年,我在 10 年后访问它。

这是输出

HTTP/1.1 200 OK
Date: Tue, 03 Oct 2017 21:50:33 GMT
Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips
Last-Modified: Fri, 31 Aug 2007 04:21:06 GMT
ETag: "c12-438f726ceb080"
Accept-Ranges: bytes
Content-Length: 3090
Content-Type: image/gif

还有java代码供引用,我用的是套接字。

Date d = new Date();
outputStream.print("HEAD "+ "/" + pathName + " HTTP/1.1\r\n");
outputStream.print("If-Modified-Since: " + d.toString() + "\r\n");
outputStream.print("Host: " + hostString+"\r\n");
outputStream.print("\r\n");
outputStream.flush();

任何帮助将不胜感激,我是 HTTP 客户端的新手。

最佳答案

您可能需要格式化用于“If-Modified-Since” header 的日期。这是语法(取自 here ):

If-Modified-Since: day-name, day month year hour:minute:second GMT

例子:

If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT

关于java - HTTP 未返回 304,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46554077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com