HTTP Error 415 Unsupported media type on a specific server - How to find the issue?

1.1k Views Asked by At

I've seen muliple posts recommending your post and put requests to specify header content-type application/json, to add or remove charset or specify content-encoding but that didn't solve the issue.

The website has been working well for the last 6-7 years, in .Net Framework 4.5.0 with jquery and knockoutjs

        $.ajax({
            url: '/api/calendrierUsager/preferences',
            type: 'PUT',
            data: JSON.stringify(calendrier.configuration.viewModel.preferences()),
            contentType: "application/json; charset=utf-8",
            success: function(result) { ... }


The oddity here is that the same code published one server has no issues, while the production server returns HTTP Error 415 - Unsupported media type for any put and post requests made to the api. simple json text payload, no file content fails

in Chrome developer console, the response from the server has this payload along with http error 415

{"Message":"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource."}

Both servers are using netscalers for load balancing. Same frameworks and windows updates.

What configurations on the server could cause the issue given that both have the same code (except config values from web.config) ?

Same code works on different servers; adding charset=utf8 or charset=utf-8 in Content-Encoding header or within content-type request header makes no changes in both environements (works on one with or without, error 415 on the other one with or without)

1

There are 1 best solutions below

0
On

The introduction of these packages in the project (packages.config) seems to have caused my issue:

<package id="Microsoft.IdentityModel.Abstractions" version="6.24.0" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Logging" version="6.24.0" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Tokens" version="6.24.0" targetFramework="net45" />

I was able to remove them (I acutally only needed Base64UrlEncoder to deal with one base64 encoded parameter in one endpoint) redeployed and problem gone.

I'm still confused why it had no issue locally and with our dev servers.

Also, if that can help, I have read from this github issue https://github.com/umbraco/Umbraco-CMS/issues/3796 : <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net45" /> produces the same error and the recommended action was to downgrade to 5.2.6