iphone - 使用 https 时,它适用于 Android 手机,但在 i-Phone 上收到错误消息:“Error Domain=NSURLErrorDomain Code=-1200”
问题描述
我的视觉工作室 Xamarin.Form 应用程序在 Android 手机中运行良好,但在 iPhone 或 iPhone 模拟器上失败,如下声明:
var content = await _client.GetStringAsync(RI_Url); // RI_Ur1 is "https://xxxxxxx"
当我将RI_Url
Safari、Chrome 和 Edge 放入时,它可以显示结果。
如果它有效RI_Uri = "http://xxxxxxx"
我试图将以下内容放在 info.plist 中,但它不起作用。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
有人会帮助解决问题吗?
谢谢。
错误信息是:
{System.Net.Http.HttpRequestException: An SSL error has occurred and a secure connection to the server cannot be made. --->
Foundation.NSErrorException: Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made."
UserInfo={NSErrorFailingURLStringKey=https://xxxxxxxxxxxxxxxxxx,
NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3,
_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <60343732-0A70-45A6-A4BB-263867134C53>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <60343732-0A70-45A6-A4BB-263867134C53>.<1>"
), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made.,
NSErrorFailingURLKey=https://xxxxxxxxxxxxxxxxxxx,
NSUnderlyingError=0x6000024cafd0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)"
UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9836, _kCFStreamErrorDomainKey=3,
_kCFStreamErrorCodeKey=-9836}}, _kCFStreamErrorCodeKey=-9836}
--- End of inner exception stack trace ---
at System.Net.Http.NSUrlSessionHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
[0x001d4] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.2.0.42/src/Xamarin.iOS/Foundation/NSUrlSessionHandler.cs:437
at System.Net.Http.HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption,
System.Threading.CancellationToken cancellationToken) [0x0009e]
in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:281
at System.Net.Http.HttpClient.GetStringAsync (System.String requestUri) [0x00033]
in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:328
at xxxxxxxxx.OnGetList () [0x00039] in C:\xxxxxxx\xxxxxxxxPage.xaml.cs:41 }
解决方案
尝试这个:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>yoururl</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
推荐阅读
- ubuntu - ffmpeg 的输出
- google-maps - Google Maps API“仅用于开发目的”
- tensorflow - 在tensorflow训练期间可以改变网络架构吗?
- reactjs - react-final-form Field 如何访问一些初始值?
- javascript - JS 正则表达式组合
- java - 连接到netbeans的数据库
- java - RxJava 是否适合分支工作流?
- javascript - 使用附加功能和正确的行号包装 console.log
- django - GeoDjango 教程错误:无法将关键字“mpoly”解析为字段
- ios - 如何在单个 UILabel 中使用多个间距