我想做一个程序,登录到一个网站,并执行一些自动化的活动。我一直在使用HttpClient 4.0.1,并使用它开始:http://hc.apache.org/httpcomponents-client/primer.html。用HttpClient登录站点Post
在这个特定的网站上,cookie不是通过“set-cookie”头设置的,而是通过javascript设置的。
到目前为止,我无法实现登录。
我尝试了以下事情:
- 手动添加标头中出现的萤火
NameValuePair[] data = { new BasicNameValuePair("Host",host), new BasicNameValuePair("User-Agent"," Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"), new BasicNameValuePair("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), new BasicNameValuePair("Accept-Language","en-us,en;q=0.5"), new BasicNameValuePair("Accept-Encoding","gzip,deflate"), new BasicNameValuePair("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7"), new BasicNameValuePair("Keep-Alive","300"), new BasicNameValuePair("Connection","keep-alive"), new BasicNameValuePair("Referer",referer), new BasicNameValuePair("Cookie",cookiestr) }; for(NameValuePair pair : data){ loginPost.addHeader(pair.getName(),pair.getValue()); }
- 创建BasicClientCookies和所有请求头使用setCookieStore进行设置。不幸的是,我不知道如何测试cookie是否实际发送。还有,有什么方法可以测试发送其他自动参数吗? (如正在模拟的浏览器等)。
我得到的回应是:HTTP/1.1 417预期失败
我还是新来这一点,所以没有人知道离手的问题可能是什么?如果没有,我会发布更多的细节,代码和网站。
我会尽力,谢谢! – humoeba 2010-01-14 16:18:24