gpt4 book ai didi

android - HttpClient VS Jsoup : Http package header look the same but not the response is difference?

转载 作者:可可西里 更新时间:2023-11-01 16:43:34 25 4
gpt4 key购买 nike

如下图是从 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)");

我尝试为每个 header 设置相同的值,包括用户代理。这是用于登录网站的包。

我的问题是由 Jsoup 创建的左侧包正在工作,但是当我使用 HttpClient 时,服务器通过登录响应不正确但请求包是相同的,为什么?

在我的 android 项目中,我必须使用 HttpClient。这是我的约束。

Package Compare

最佳答案

您可能必须在 StringEntity 对象中设置内容类型。另外,为什么要制作 BasicNameValuePairs 然后只使用字符串?

关于android - HttpClient VS Jsoup : Http package header look the same but not the response is difference?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17746067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com