无法从我的 Android 模拟器访问 HTTPS

Vic*_*ira 6 https proxy android android-emulator react-native

我支持公司代理,并且访问 Internet 的所有内容都需要有关代理的特殊配置。我在 CentOS 7 上,使用 CNTLMD 处理代理隧道,使用 React Native 为移动设备开发。我正在使用 Android Studio 提供的 Android Emulator。

当我尝试在浏览器中打开 Google 时,我首先注意到我的模拟器无法访问任何 HTTPS 协议。谷歌内部重定向到 HTTPS,我总是收到“连接被拒绝”错误。稍后(本周),尝试使用 Axios 和 Fetch 进行 HTTP/HTTPS 请求,这已成为一个严重的问题,因为我尝试连接的 API 是在 HTTPS 协议下。

我的一个朋友在同一个项目中工作但使用 Mac,HTTPS 没有问题。我还尝试使用以下命令启动模拟器:

emulator -avd myemulator -http-proxy http://127.0.0.1:3128
Run Code Online (Sandbox Code Playgroud)

emulator -avd Marshmallow86 -http-proxy http://<network username>:<network password>@<ip>:<port>
Run Code Online (Sandbox Code Playgroud)

他们什么都不做。

我尝试在 Android Studio 上设置 HTTP 和 HTTPS 代理,但这似乎不是这样(并且也不起作用)。

@编辑

我在我的主机上设置了 http_proxy 并在没有参数的情况下启动了模拟器。也没有奏效。

我错过了什么?

nic*_*ole 2

我没有使用过上面不是 android avd 或 androidstudio 的软件,但它看起来像是代理或 CA 证书问题。由于差异似乎是由操作系统决定的,所以我首先猜测 CA 证书。

此 Android 页面提供了有关从命令行使用 openssl 进行探索并考虑导入证书的建议。

https://developer.android.com/training/articles/security-config.html

此 Android 页面提供了代理配置的最新建议: https://developer.android.com/studio/run/emulator-networking.html

请注意,上述说明已针对新功能进行更新。过去,我需要一个非 ssl appengine 开发服务器的代理,这与您的问题略有不同,但这是我使用的:

对于 SSL 代理,使用 apache Web 服务器,并通过安装自签名证书将其配置为使用 SSL,然后在 httpd.conf 中添加 ProxyPass 和 ProxyPassReverse,并在 httpd-ssl.conf 中添加 ProxyPass。代理通行证 / http://127.0.0.1:8080/

Apache 作为 SSL 代理接收到https://127.0.0.1:443的连接并将其传递到http://127.0.0.1:8080

然后在应用程序中,将在模拟器中运行的代码可以使用地址 10.0.2.2 来使用 android 子网路由表连接到开发设备。操作系统本地主机。