Search code examples
c#apigetbackend

Error 415 The request contains an entity body but no Content-Type header


When sending a GET request to the API url the following error is shown:

{"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."}

and in chrome console:

Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)

How it is possible to solve this? I am not sure what to look for.


Solution

  • I'd leave a comment but I don't have enough reputation yet.

    I'm assuming you've made a REST API in C# and are trying to test it?

    It seems to me that the backend is expecting a header with Content-Type specified. For example, if you're sending JSON in the body the Content-Type would be JSON.

    For testing these kind of things I personally use postman, rather than executing the requests through chrome, since it allows you to set up the HTTP requests more specifically. Other tools would work too though.

    The postman docs here cover setting the Content-Type in a HTTP request. https://learning.postman.com/docs/sending-requests/requests/#configuring-request-headers