1

We have a REST API which maps third-party proprietary language codes (in the en-US format) into language codes that our own system recognises. The REST API's route is

~/v1/languages/mappings/{foreignLanguageCode} [GET]

We receive these third-party language codes and send them to our own API using an instance of System.Net.Http.HttpClient.

This is working perfectly well for many language codes but when passed ko-US the request doesn't even get sent - the HttpClient object throws the exception

An error occurred while sending the request.

The inner exception - a WebException - says

The server committed a protocol violation. Section=ResponseStatusLine

The exception also contains

Source: "System"
Status: ServerProtocolViolation
StackTrace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)

The URI at this point is

https://www.example.com/api/v1/languages/mappings/ko-US/

I've tried it with and without that trailing slash: no difference. We can send many other language codes to the same API without any problem.

Can anyone explain why this particular URI causes this exception?

awj
  • 7,482
  • 10
  • 66
  • 120
  • Is the server crashing or emitting any diagnostics? You may have to sniff the wire to gain sufficient clues what is going on with that. – jwdonahue Feb 03 '20 at 20:49
  • The request isn't being sent, the server isn't being hit; there's nothing on the wire to sniff. – awj Feb 03 '20 at 20:59
  • > The server committed a protocol violation – jwdonahue Feb 03 '20 at 21:00
  • It's possible the client is lying because it's really had some internal error of some kind, but the only way to know that is to debug it. – jwdonahue Feb 03 '20 at 21:02
  • I've just checked with Fiddler and no request was sent to the expected URI - not just that specific path but the server. – awj Feb 03 '20 at 21:08
  • Is it possibly related to [this](https://stackoverflow.com/questions/2482715/the-server-committed-a-protocol-violation-section-responsestatusline-error)? – jwdonahue Feb 03 '20 at 22:00
  • Your code is running in a server context? – jwdonahue Feb 03 '20 at 22:07

1 Answers1

0

Answering my own question...

I can't really explain why but this solved the problem:

myHttpClient.DefaultRequestHeaders.ConnectionClose = true;

I added that immediately before sending the request, so the working code looks like this:

httpClient.DefaultRequestHeaders.ConnectionClose = true;
var response = await httpClient.GetAsync(uri).ConfigureAwait(false);
awj
  • 7,482
  • 10
  • 66
  • 120