你的代码在我的测试下运行良好。
当提供正确的 cookie 时,我的测试网站 weibo.com 将强制通过 HTTP 302 重定向。
关闭自动重定向后,响应标头为
Transfer-Encoding: chunked
Connection: close
Pramga: no-cache
DPOOL_HEADER: dagda24
Cache-Control: no-cache, must-revalidate
Content-Type: text/html
Date: Thu, 13 Mar 2014 15:07:53 GMT
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Thu, 13 Mar 2014 15:07:53 GMT
Location: /u/2398332747/home?wvr=5
Server: nginx
并且网页没有明显重定向。
启用自动重定向后,响应标头为:
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Pragma: no-cache
DPOOL_HEADER: balor165
Cache-Control: no-cache, must-revalidate
Content-Type: text/html; charset=utf-8
Date: Thu, 13 Mar 2014 15:13:26 GMT
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Server: nginx
网页内容验证请求是否已重定向。
我确实注意到位置标头的第一个字母是大写的。这个没有测试header格式是否相关。
Edit:
最后,对 example.com 进行了测试,但在我的环境下它根本没有触发重定向。这就是为什么我选择 weibo.com 作为替代方案。
Edit:
我对此做了一些更多的研究,根据 RFC 2616,标头不区分大小写。你的代码对我来说很好,但仍然不知道为什么会出错。希望其他人给个指导。