vue axios post request 415 (Unsupported Media Type)

1. When using axois to request the backend interface in the vue project, an error is reported Unsupported Media Type (the media type is not supported)

2. The reason for the error

2.1 The parameter passed is in Json format, but the axios post request is not in Json format, resulting in an error of 'unsupported media type'

 2.2 View the browser network request, the response header is missing a Content-Type response type

3. Error resolution, where axios is introduced, usually in main.js, add the following request header configuration

3.1 Add request header configuration

axios.defaults.headers.post['Content-Type']='application/json;charset=UTF-8';

 3.2 Then the request is successful

This is how I solved this problem.

reference article

Guess you like

Origin blog.csdn.net/weixin_39237340/article/details/128642735