简体   繁体   English

无法使用 charles 代理查看 iOS 模拟器流量

[英]Cannot see iOS simulator traffic with charles proxy

I have installed Charles proxy, then installed the root certificate and root certificate for iOS simulator.我已经安装了 Charles 代理,然后安装了 iOS 模拟器的根证书和根证书。 Then I ran the application of the simulator but I cannot see any request inside charles.然后我运行了模拟器的应用程序,但我在 charles 内部看不到任何请求。

When I curl the same request with proxy it shows up in the Charles当我使用代理卷曲相同的请求时,它出现在查尔斯

curl --proxy 127.0.0.1:8888 -k -v https://example.com

There is no need to use curl.无需使用 curl。

Xcode simulators use the host OS's network settings so when you change anything in the (macOS) System Preferences or in the Charles Proxy app, you have to restart the simulator. Xcode 模拟器使用主机操作系统的网络设置,因此当您在 (macOS) 系统偏好设置或 Charles Proxy 应用程序中更改任何内容时,您必须重新启动模拟器。

You should complete the following settings:您应该完成以下设置:

  1. Enable this option in the Charles app: Proxy > macOS Proxy (It will set your localhost as a proxy on the (macOS) System Preferences > Network > Advanced > Proxies tab)在 Charles 应用程序中启用此选项:代理 > macOS 代理(它会将您的本地主机设置为 (macOS) 系统偏好设置 > 网络 > 高级 > 代理选项卡上的代理)

  2. On iOS 10.3 or later, navigate to Settings > General > About > Certificate Trust Settings on your phone/simulator and enable full trust for the Charles Proxy certificate.在 iOS 10.3 或更高版本上,导航到手机/模拟器上的设置 > 常规 > 关于 > 证书信任设置,并为 Charles Proxy 证书启用完全信任。

  3. Restart the Xcode Simulator重启 Xcode 模拟器

New16 may be on to something - New16 可能正在做点什么——

Not sure which simulator you use, but I assume that it uses your Mac's internet connection, unlike real devices that connect to Charlesproxy through the http port that you specify (8888 by default).不确定您使用的是哪个模拟器,但我假设它使用您 Mac 的互联网连接,这与通过您指定的 http 端口(默认为 8888)连接到 Charlesproxy 的真实设备不同。

While http traffic proxied through that port will always be recorded by Charles, recording the traffic of desktop apps like your simulator is optional.虽然通过该端口代理的 http 流量将始终由 Charles 记录,但记录模拟器等桌面应用程序的流量是可选的。 Thus the simulator's traffic will only be recorded if you check the corresponding option in the "Proxy" menu.因此,只有在“代理”菜单中选中相应选项时,才会记录模拟器的流量。 (In Charles on Windows, the available options are "Windows Proxy" and "Firefox Proxy", not sure what are the options on a Mac.) (在 Windows 上的 Charles 中,可用选项是“Windows 代理”和“Firefox 代理”,不确定 Mac 上的选项是什么。)

While you have done the other steps for macOS Proxy and Certificate Trust Settings etc, one important thing to validate is adding ATS flag to your debug build:虽然您已经完成了 macOS 代理和证书信任设置等的其他步骤,但要验证的一件重要事情是将 ATS 标志添加到您的调试版本中:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

You must remember to re-enable ATS before you release your app to take advantage of the security that ATS provides.您必须记住在发布应用程序之前重新启用 ATS,以利用 ATS 提供的安全性。

Best place to troubleshoot any Charles configuration issue: https://www.charlesproxy.com/documentation/faqs/解决任何 Charles 配置问题的最佳位置: https ://www.charlesproxy.com/documentation/faqs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM