【发布时间】:2011-02-09 04:21:48
【问题描述】:
我通过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。在上述情况下,重定向的 url 是copenhagen.craigslist.org
是否有任何标准方法可以让我确定特定 url 将重定向到哪个 url。
我知道当一个 url 重定向到另一个 url 时,服务器会发送一个包含 Location 标头字段的中间响应,该字段告诉重定向的 url,但我没有通过 url.openConnection(); 方法接收到该中间响应。
【问题讨论】:
标签: java url http-headers