1
我正在通过Websphere App Server(7FP19)从IBM HTTP服务器请求文件。对于大多数文件,我得到的内容长度标题,但一些,而不是。我发现,当我将请求中最后修改的值设置为'0'时,我得到所有文件的内容长度。为什么HTTP头'content-length'不总是被设置?
这对我来说似乎有点奇怪。有谁知道为什么这可能是或仅仅是一个巧合?
下面是一些代码:
connection = (HttpURLConnection) url.openConnection();
for (String value : cookies.values()) {
connection.addRequestProperty("Cookie", value); //$NON-NLS-1$
}
connection.setDoOutput(true);
connection.setRequestProperty("User-Agent", USER_AGENT); //$NON-NLS-1$
//connection.setIfModifiedSince(localLastModified);
connection.setIfModifiedSince(0);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(post);
wr.flush();
wr.close();
....
// set file attributes
long remoteDate = connection.getLastModified();
if(rc == 304)
data.lastModified = localLastModified;
else
data.lastModified = remoteDate;
data.retCode = connection.getResponseCode();
data.contentType = connection.getContentType();
data.contentEncoding = connection.getContentEncoding();
int expectedLength = connection.getContentLength();
if(expectedLength < 0) {
log.warn("Expected length: " + expectedLength);
}
UPDATE
这是上Wesphere FP19运行。我回到了FP15,问题没有了。长度总是返回。
不,我得到一个200 – paul
你能包含完整的请求和响应头文件吗? – covener