我当前正在请求oracle网站从我的应用程序下载java,我检查是否使用If-None-Match标记发送本地文件的ETag更新了本地文件。服务器以以下格式向我返回了ETag:“ acd45017cd055c797a331b2f0652d293:1539062148.210488”,它是etag:最后修改的。
在这种情况下,服务器应该返回304,但始终返回200,因为我的本地ETag“ acd45017cd055c797a331b2f0652d293”与服务器ETag“ acd45017cd055c797a331b2f0652d293:1539062148.210488”不匹配
protected HttpURLConnection makeConnection(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setUseCaches(false);
connection.setDefaultUseCaches(false);
if (!shouldIgnoreLocal() && getTarget().isFile())
connection.setRequestProperty("If-None-Match", getDigest(getTarget(), "MD5", 32));
connection.setRequestProperty("Cookie", "oraclelicense=accept-securebackup-cookie");
connection.setRequestProperty("Cache-Control", "no-store,max-age=0,no-cache");
connection.setRequestProperty("Expires", "0");
connection.setRequestProperty("Pragma", "no-cache");
connection.setConnectTimeout(5000);
connection.setReadTimeout(30000);
int status = connection.getResponseCode();
while (status != HttpURLConnection.HTTP_OK && (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER)) {
String newUrl = connection.getHeaderField("Location");
connection = makeConnection(new URL(newUrl));
status = connection.getResponseCode();
}
System.out.println(connection.getHeaderField("Last-Modified"));
System.out.println(connection.getHeaderField("If-None-Match"));
System.out.println(connection.getHeaderField("ETag"));
System.out.println(connection.getResponseCode());
System.out.println(connection.getHeaderField("Last-Modified"));
System.out.println(connection.getHeaderField("If-None-Match"));
System.out.println(connection.getHeaderField("ETag"));
System.out.println(connection.getResponseCode());
return connection;
}