从Xamarin iOS连接到特定服务器的超时

时间:2016-04-01 12:49:01

标签: ios https xamarin timeout dotnet-httpclient

我有一个Xamarin iOS应用程序在连接到我们的许多内部https服务器时达到超时(10分钟)。应用程序用于连接的代码是:

HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, uri);

[Headers and content are added to message here - I can't easily post up
the details for security reasons, but if anyone thinks that that might
be causing the problem, I'll work something out.]

System.Net.Http.HttpClientHandler handler = new System.Net.Http.HttpClientHandler();
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(handler);
client.MaxResponseContentBufferSize = 900000000;
client.Timeout = TimeSpan.FromSeconds(600);

HttpResponseMessage response = await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead);

我在超时时收到的消息是:A task was cancelled

我已经对此进行了相当多的研究,这些是我的发现:

  1. 此代码也用于连接服务器的Windows应用程序。
  2. 我已经从原生iOS应用程序连接到此服务器。
  3. 当我尝试通过Fiddler连接设置为解密HTTPS流量时,它可以正常工作。
  4. 我已将App Transport Security添加到应用的Info.plist中,从而关闭了App Transport:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
    
  5. 我从与iOS模拟器相同的机器上运行了ATS诊断工具(/usr/bin/nscurl --ats-diagnostics [URL]),一切都过去了。

  6. 我更新到Xamarin的alpha轨道以获取Xamarin.iOS 9.8 HTTP changes但仍然有超时。(见下面的评论)
  7. 我可以从应用程序连接到其他内部服务器。我在损坏的服务器和两个工作服务器上使用SSL labs' tester运行测试,发现损坏的服务器不支持TLS 1.1和RC4,而工作服务器则支持。然后我尝试在其中一个工作服务器上关闭这两个以试图打破它,但我仍然可以连接。
  8. 任何想法还有什么可能是问题以及我还能尝试什么?!我突然强调了上面关于Fiddler的观点,因为我怀疑它可能是一个很大的线索 - 当服务器在解密模式下通过Fiddler连接时,服务器与应用程序有何不同?

0 个答案:

没有答案