我正在通过Java访问网页,如下所示:
URLConnection con = url.openConnection();
但是在某些情况下,一个URL重定向到另一个URL。所以我想知道以前的URL重定向到的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 。在上述情况下,重定向的网址为copenhagen.craigslist.org
有什么标准方法可以确定特定的URL将要重定向到哪个URL。
我知道,当一个URL重定向到其他URL时,服务器会发送一个中间响应,该响应包含一个Location标头字段,该字段告诉重定向的URL,但我没有通过该url.openConnection();方法收到该中间响应。