0

I have a XML-RPC server (using XML-RPC.net) running as a .NET console application. I'm trying to connect to it via my ASP.NET Core (2.1.1) web app but the client keeps timing out. Postman also returns a response immediately without issues.

Here is how I'm calling it:

        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();

I can see that the request was made successfully as the console app returns a response. Fiddler shows there was a 200 response but await client.SendAsync(httpRequest); times-out!

The request usually completes in under 10ms so the timeout value is just for debugging, if I leave it out it would take 60s. The response returns XML.

I've tried rewriting this to use StringContent and using PostAsync, same issue. I also attempted to rewrite this using WebClient but it returned The remote server returned an error: (100) Continue. not sure if that's relevant.

Been stuck on this for a whie, anyone know what could be happening?

Yodacheese
  • 4,787
  • 5
  • 34
  • 42

1 Answers1

1

OK I did some googling and it looks like I needed this line:

client.DefaultRequestHeaders.ExpectContinue = true;

It was definitely related to 100 status code returned not being handled properly.

Found it here: https://social.msdn.microsoft.com/Forums/en-US/042016f0-d70e-42f9-9924-5febeb2bea86/excluding-the-quotexpect-100continuequot-header-from-httpwebrequest-posts?forum=winappswithcsharp

Yodacheese
  • 4,787
  • 5
  • 34
  • 42