HTTP 415 Unsupported Media Type

HTTP 415 Unsupported Media Type

  • Posted on: September 20, 2015
  • By:

Encountered an error in IE11 a while ago using the Swagger UI, on a DELETE REST request, which returned “HTTP 415 Unsupported Media Type” error, while Firefox/Chrome had no problem with the same request (I know, what else is new, right?). I couldn’t find anything specific around Swagger and HTTP 415.
As it turns out, Swagger gets its payload data using var data = this._formData || this._data; in Request.prototype.end, but on a DELETE there is no data, so “data” is undefined. Later on it does its XHR request xhr.send(data);.
No problem in Firefox/Chrome, but IE11 sends back the string "undefined" as data, and the server isn’t expecting anything like that, hence the “HTTP 415 Unsupported Media Type” response.
Explicitly setting the data to null var data = this._formData || this._data || null; in the Swagger UI JavaScript fixed it (or not sending the data when it’s undefined in the xhr would work around it too). Though it rather looks like an IE bug, no?