【发布时间】:2013-07-19 12:26:40
【问题描述】:
如下图从 Wireshark 截取的,左边是这个代码从 Jsoup 创建的包。
Connection.Response response = Jsoup.connect("http://pantip.com/login/authentication")
.header("Content-Type", "application/x-www-form-urlencoded")
.timeout(9000)
.method(Connection.Method.POST)
.data("member[email]", username, "member[crypted_password]", password, "action", "login", "redirect", "")
.followRedirects(false)
.execute();
右侧是通过以下代码从 HttpClient 创建包。
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("member[email]", username));
nvps.add(new BasicNameValuePair("member[crypted_password]", password));
nvps.add(new BasicNameValuePair("action", "login"));
nvps.add(new BasicNameValuePair("redirect", ""));
HttpPost postLogin = new HttpPost("http://pantip.com/login/authentication");
postLogin.setEntity(new StringEntity("member[email]="+username+"&member[crypted_password]="+password+"&action=login&redirect="));
postLogin.addHeader("Content-Type", "application/x-www-form-urlencoded");
postLogin.addHeader("Accept-Encoding", "gzip");
postLogin.addHeader("User-Agent", "Dalvik/1.4.0 (Linux; U; Android 2.3.7; Full Android on x86 Emulator Build/GINGERBREAD)");
我尝试将每个标头设置为包含用户代理的相同值。这是登录网站的包。
我的问题是 Jsoup创建的左侧包在工作,但是当我使用HttpClient时,登录服务器响应不正确但请求包相同,为什么?
在我的 android 项目中,我必须使用 HttpClient。这是我的约束。
【问题讨论】:
标签: android http network-programming httpclient jsoup