Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Http request 415 error Unsupported Media Type what to do

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report