我有一个由Xamarin Studio开发的iOS应用程序。 当我尝试从服务器获取字符串时,我得到以下异常。
Exception in Class: WebClient
Line : 271
and Method:DownloadDataCore
with message Error: SendFailure (Error writing headers)
Stack Trace: at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00065] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.2.0.207/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:971
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.2.0.207/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:985
at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.2.0.207/src/mono/mcs/class/System/System.Net/WebClient.cs:1563
at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.2.0.207/src/mono/mcs/class/System/System.Net/WebClient.cs:972
at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x0000a] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.2.0.207/src/mono/mcs/class/System/System.Net/WebClient.cs:271
当我尝试从非SSL网站下载字符串时,可以正常加载字符串。
网站证书完全有效,Safari在模拟器和OSX中都不会拒绝。
我在模拟器上运行应用程序。
如果你能帮助我解决问题,我将非常感激。
我用来从服务器获取字符串的代码是:
System.Net.ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
WebClient wc = new WebClient ();
wc.CachePolicy = new System.Net.Cache.RequestCachePolicy (System.Net.Cache.RequestCacheLevel.NoCacheNoStore );
result = wc.DownloadString (Url);
此致
答案 0 :(得分:0)
在使用mono访问SSL站点之前,您必须运行mozroots --import --sync
以导入mozilla可信证书列表。
此外,还有mono security FAQ可以帮助解决SSL问题。