0

I have a .NET 4.6.1 client application that uses HttpWebRequest to call a WebAPI hosted on IIS. One of the calls is a POST request without a body that does not set the ContentLength header (HttpWebRequest.ContentLength has its default value -1, which indicates the property has not been set and that there is no request data to send).

  • When I send this request to the WebAPI application hosted on IIS 8.5, the POST request works normally.
  • Until recently, I was also able to send the request to the WebAPI running on IIS Express under the Visual Studio 2017 debugger, and again, it worked normally. Unfortunately I no longer know exactly which version of IIS Express was being used.

Recently I repaved my development machine with Windows 10 Version 1909 and reinstalled the latest Visual Studio 2017 15.9.22. Since doing this:

  • Requests sent from by development machine to the WebAPI hosted remotely on IIS 8.5 continue to work normally.
  • Requests sent to the WebAPI running locally on IIS Express 10.0.14358.1000 under the Visual Studio 2017 debugger are rejected with 411 LengthRequired.

I know that I can (and will eventually) fix this by modifying my client code to set ContentLength = 0.

But the client code is out in the field, and I'd like to fix this server-side if possible, e.g. by configuring IIS Express appropriately.

This looks to me like a breaking change in IIS behavior between IIS 8.5 and IIS Express 10.0.14358.1000, in that the latest IIS Express appears to be more restrictive in refusing to accept a POST without ContentLength header.

Is there a way of configuring IIS Express to behave as it used to? Or some other way of fixing this without modifying client code?

Joe
  • 122,218
  • 32
  • 205
  • 338
  • Actually returning 411 is compliant to HTTP standard as well as other web server implementations, so I don't think there is an easy way to let IIS Express use the old behavior. – Lex Li May 05 '20 at 18:04

1 Answers1

1

If you review the request, you will see that the response is not returned from IIS but http.sys HTTP-API/2.0.

enter image description here

Since there is no registry can fix this, I'm afraid the only way to fix 411 is modify you client code. Otherwise, IIS express can't even accept the request.

https://support.microsoft.com/en-us/help/820129/http-sys-registry-settings-for-windows

Jokies Ding
  • 3,374
  • 1
  • 5
  • 10
  • So that seems to imply that upgrading Windows on a web server could break previously working applications. I'd really like ot know what version of Windows / http.sys introduces this breaking change. My development machine has http.sys 10.0.18362.295 – Joe May 06 '20 at 07:08
  • Emmm.. I'm not able to post a request without content length even in an older WIN7 server. So I'm not sure whether this issue have something to do with IIS express or http.sys. It should be a standard behavior to handle the post request. Have you monitored the request header with fiddler in IIS 8.5 environment? Maybe the content-length get fixed in intermediate process. – Jokies Ding May 06 '20 at 08:18
  • Your analysis is correct, it must be something intermediate that's fixing the header. – Joe May 06 '20 at 10:04