0

我有一个作为 .NET 控制台应用程序运行的 XML-RPC 服务器(使用 XML-RPC.net)。我正在尝试通过我的 ASP.NET Core (2.1.1) Web 应用程序连接到它,但客户端一直超时。邮递员也会立即返回响应,没有问题。

我是这样称呼它的:

        HttpClient client = _clientFactory.CreateClient();

        client.Timeout = TimeSpan.FromSeconds(10);

        var httpRequest = new HttpRequestMessage(HttpMethod.Post, instance.ServiceUrl);
        var stringContent = new ByteArrayContent(Encoding.UTF8.GetBytes(request.ToString()));

        httpRequest.Content = stringContent;
        httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml");

        var httpResponse = await client.SendAsync(httpRequest);
        var response = await httpResponse.Content.ReadAsByteArrayAsync();

当控制台应用程序返回响应时,我可以看到请求已成功发出。Fiddler 显示有 200 响应但await client.SendAsync(httpRequest);超时!

请求通常在 10 毫秒内完成,因此超时值仅用于调试,如果我将其忽略,则需要 60 秒。响应返回 XML。

我试过重写这个来使用StringContent和使用PostAsync,同样的问题。我也尝试使用重写它,WebClient但它返回The remote server returned an error: (100) Continue.不确定这是否相关。

一直卡在这个问题上,有人知道会发生什么吗?

4

1 回答 1

0

好的,我做了一些谷歌搜索,看起来我需要这条线:

client.DefaultRequestHeaders.ExpectContinue = true;

这肯定与返回的 100 状态码未正确处理有关。

在这里找到它: https ://social.msdn.microsoft.com/Forums/en-US/042016f0-d70e-42f9-9924-5febeb2bea86/ exclude-the-quotexpect-100continuequot-header-from-httpwebrequest-posts?forum= winappswithcsharp

于 2018-08-02T23:37:42.897 回答