時,我得到以下網址與捲曲重定向與捲曲/ HttpClient的:頭 「位置」 失蹤
curl -D headers.http "http://www.springerlink.com/index/10.1007/s00453-007-9157-8"
文件headers.http包含一個 「位置」 標題:
HTTP/1.1 302 Found
Date: Tue, 27 Oct 2009 17:00:20 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Location: http://www.springerlink.com/link.asp?id=c104731297q64224
Set-Cookie: CookiesSupported=True; expires=Wed, 27-Oct-2010 17:00:20 GMT; path=/
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 173
但是當我使用apache httpclient庫時,這個「Location:」頭部缺失(?)。
int status = httpClient.executeMethod(method);
if(status!=HttpStatus.SC_OK &&
status!=HttpStatus.SC_MOVED_TEMPORARILY &&
status!=HttpStatus.SC_MOVED_PERMANENTLY
)
{
throw new IOException("connection failure for "+url+" status:"+status);
}
Header header=method.getResponseHeader("Location");
if(header==null)
{
for(Header h:method.getResponseHeaders())
{
LOG.info(h.toString());
}
throw new IOException(
"Expected a redirect for "+url
);
}
我列出以下標題:
INFO: Date: Tue, 27 Oct 2009 17:05:13 GMT
INFO: Server: Microsoft-IIS/6.0
INFO: X-Powered-By: ASP.NET
INFO: X-AspNet-Version: 2.0.50727
INFO: Set-Cookie: ASP.NET_SessionId=js1o5wqnuhuh24islnvkyr45; path=/; HttpOnly
INFO: Cache-Control: private
INFO: Content-Type: text/html; charset=utf-8
INFO: Content-Length: 17245
噓???
使用我的curl版本「-D/- 轉儲標題將標題寫入此文件」。它不是「僅標題」。有或沒有-D,結果是一樣的。 –
Pierre
2009-10-27 17:55:46
所以它看起來像低級curl命令不是跟隨重定向,而你的Java捲曲客戶端。它。 – davethegr8 2009-10-27 18:15:06