Get the App
SLTechnology News&Howtos  ›  Development  › 

Http request 415 error Unsupported Media Type what to do

Shulou Source: shulou.com Published: 2022-06-03 11:02:53 09月25日 Update

Editor to share with you http request 415 error Unsupported Media Type how to do, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Http request 415 error UnsupportedMediaType

The wrong explanation is that the server cannot handle the media format attached to the request and does not understand what it means. At first, I thought that the background setting could not be parsed. Later, I used postman and swagger to request successfully. I confirmed that it was my request. I looked at the HTTP request header file and found that content-type was different from our json format.

So add content-type to application/json in the ajax request, and then remember to format the array object as the json object JSON.stringify ()

Ask again, OK.

HTTP request 415 error-unsupported media type (Unsupportedmediatype)

There are usually the following situations:

1: check your http request header, for example, the request was rejected because User-Agent was set by the server

For example, the crawler you wrote is likely to be rejected because it is not disguised as a browser.

User-agent details

2: check your http request method and server-side settings

For example, there is an interface that enforces post requests. Do you use non-post requests?

3:post request parameter setting, is not required, json format

For example, the following two pieces of code

The following json parameter, body

Or look at whether the background controller receives json or body. If the background is received by body, the foreground must submit it with form.

415 (UnsupportedMediaType)

Query data and found that contentType is not set.

Content-Type is not set to Json when 1.Ajax request.

two。 Do not convert the content of the request sent to a JSON object, just send a JSON string directly, otherwise it will be a 415 error!

Change the code:

Functiontest () {

$.ajax ({

Type: "POST"

Async:false

ContentType:'application/json'

Data:' [{"key": "displayName", "value": ["NE32003"]}, {"key": "hasLabel", "value": ["1"]}]'

Success:function (data) {

The above is all the contents of the article "what to do with http request 415 error Unsupported Media Type". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Error format content background object server article service how to do code parameter media different successful not so foreground method most header character Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS NVidia Linux Huawei