我的视觉工作室Xamarin.Form App在Android Phone上运行正常,但在以下声明中在iPhone或iPhone Simulator上失败:
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>