【发布时间】:2019-01-10 19:06:17
【问题描述】:
我有一个作为 .NET 控制台应用程序运行的 XML-RPC 服务器(使用 XML-RPC.net)。我正在尝试通过我的 ASP.NET Core (2.1.1) Web 应用程序连接到它,但客户端一直超时。 Postman 也会立即返回响应而不会出现问题。
我是这样称呼它的:
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. 不确定这是否相关。
暂时卡在这个问题上,有人知道会发生什么吗?
【问题讨论】:
标签: asp.net .net .net-core xml-rpc.net