【发布时间】:2014-11-15 07:54:39
【问题描述】:
我有一个由 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 网站下载字符串时,一切正常,加载字符串没有任何问题。
网站证书完全有效,在模拟器和 OSX 中都没有被 Safari 拒绝。
我正在模拟器上运行应用程序。
如果您能帮我解决问题,我将不胜感激。
我用来从服务器获取字符串的代码是:
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);
问候
【问题讨论】:
-
可能是服务器不接受 TLS 1.0(或 SSL 3)。你能给我们你想访问的 URL 吗?
-
@poupou 很抱歉,我无法在此处分享链接,请告诉我您需要我网站认证中的哪些信息来帮助我解决问题?我会在这里分享。非常感谢
-
这与您的证书无关,而与您的服务器的设置方式有关。确保它接受 TLS 1.0 连接(例如使用其他软件)。
-
@poupou 这是服务器的协议测试结果: Protocols TLS 1.2 Yes TLS 1.1 No TLS 1.0 No SSL 3 No SSL 2 No
标签: ios ssl xamarin.ios xamarin webclient