我通过java访问网页如下:
URLConnection con = url.openConnection();
但在某些情况下,网址重定向到另一个网址。所以我想知道以前的URL重定向的网址。
下面是我作为响应的标题字段:
null-->[HTTP/1.1 200 OK]
Cache-control-->[public,max-age=3600]
last-modified-->[Sat, 17 Apr 2010 13:45:35 GMT]
Transfer-Encoding-->[chunked]
Date-->[Sat, 17 Apr 2010 13:45:35 GMT]
Vary-->[Accept-Encoding]
Expires-->[Sat, 17 Apr 2010 14:45:35 GMT]
Set-Cookie-->[cl_def_hp=copenhagen; domain=.craigslist.org; path=/; expires=Sun, 17 Apr 2011 13:45:35 GMT, cl_def_lang=en; domain=.craigslist.org; path=/; expires=Sun, 17 Apr 2011 13:45:35 GMT]
Connection-->[close]
Content-Type-->[text/html; charset=iso-8859-1;]
Server-->[Apache]
所以目前,我从Set-Cookie头字段的值构造重定向的url。在上面的情况下,重定向的url是copenhagen.craigslist.org
有没有任何标准的方式,通过它我可以确定哪个url特定的URL将重定向。
我知道当一个url重定向到其他url,服务器发送一个中间响应包含一个Location头字段告诉重定向的url,但我没有通过url.openConnection()接收中间响应;方法。