我为Android模拟器设置了Fiddler2,它可以工作,我可以通过Android浏览器看到HTTPS流量,但我无法使用HttpsURLConnection连接到HTTPS服务器:
// use Fiddler's proxy:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("172.16.4.20", 8888));
HttpsURLConnection connection = (HttpsURLConnection) new URL(url)
.openConnection(proxy);
connection.setRequestMethod(method);
connection.setRequestProperty("Content-Type", contentType);
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStream out = connection.getOutputStream();
我得到了:
java.net.SocketException: Socket is closed
在Fiddler中,我可以看到第一个请求(我删除了主机地址)
CONNECT [address]:443 HTTP/1.1
Host: [address]
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.0.4; Android SDK built for x86 Build/IMM76D)
Connection: Keep-Alive
After the client received notice of the established CONNECT, it failed to send any data.
响应:
HTTP/1.1 200 Connection Established
FiddlerGateway: Direct
StartTime: 12:32:18.567
Connection: close
上述请求响应对与任何其他Android浏览器HTTPS连接建立一样。
之后我无法发送POST请求(因为我收到了SocketException)。没有代理就可以了。
答案 0 :(得分:0)
最可能的解释是客户端正在关闭连接,因为它对Fiddler的HTTPS解密证书不满意。您是否已将设备配置为信任FiddlerRoot.cer证书文件?您是否已将事件处理程序附加到HttpsURLConnection以接受Fiddler的自签名证书?
答案 1 :(得分:0)
我在iphone上遇到了同样的问题。
我所做的是访问此网址ht_tp(删除得分不足)://(replace_with_the_ip_of_the_host_where_fiddler_is_running):8888
来自您的移动设备(在您的情况下是您的模拟Android设备)
然后,您将显示此链接中所述的网页
click this
您需要安装证书。之后,您将在fiddler中显示响应。
享受!
答案 2 :(得分:0)
原因可能是该应用使用证书固定。它不是信任设备“信任存储”中的任何证书,而是配置为仅信任特定证书(由服务器签名)。
因此,当Fiddler提供自己的证书时,客户端会引发错误。
更多详情:https://security.stackexchange.com/questions/29988/what-is-certificate-pinning