gpt4 book ai didi

java - 如何知道从android发送到服务器的数据包

转载 作者:行者123 更新时间:2023-11-30 04:11:02 25 4
gpt4 key购买 nike

我使用以下代码向服务器发送请求:

HttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("localhost", 8080),
new UsernamePasswordCredentials("username", "password"));

HttpHost targetHost = new HttpHost("www.myhost.com", 443, "https");
targetHost .setHeader("Accept-Language", "en-us,en;q=0.5");
targetHost .setHeader("Accept-Encoding", "gzip,deflate");
targetHost .setHeader("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");
StringEntity se = new StringEntity(myRequestData, "UTF8");
se.setContentType("text/xml");
se.setContentEncoding("gzip,deflate");
targetHost .setEntity(se);
httpclient.excute(targetHost);

问题是我想准确地查看发送到服务器的内容( header 、数据...)以及来自服务器的响应包。我知道 Wireshark 可能有帮助,但我不知道如何将它用于我的 android 代码。我需要一些示例或教程来做到这一点,或者可能有其他解决方案。提前致谢!
P/S: 我没有管理员权限,无法控制服务器。

最佳答案

当然,学习如何使用 Wireshark 不会有什么坏处。有空的话学习资料很多on the project's site ,包括视频。

如果您时间紧迫,尤其是因为您通过 SSL 连接,我认为实现一个“虚拟”服务器打印它接收到的任何内容并指向您的 Android 代码会更快连接到它Here's a refresher在 Java 的服务器端套接字上。您还可以从 execute's method return value 获取实际服务器的响应。 .

关于java - 如何知道从android发送到服务器的数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10861371/

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