angular.js - When requesting a restful api via GET, do you need to configure the content-type attribute in the header?
天蓬老师
天蓬老师 2017-05-15 17:07:41
0
3
709

The Java side provides a restful api, and the GET method returns a json. When I use postman to test, I must bring content-type: application/json in the header to succeed, otherwise it will report 415 unsupported media type.
I have a question here. This GET request does not take any parameters. Why do we need to set the content-type?
In addition, I used Angular’s ​​$http.get to access this API, and the content-type I configured in the request header seemed to be automatically cleared. Please answer your questions, thank you!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
迷茫

The content type set in request.header represents the data format of the request parameters agreed between the server and the client. The server handles exceptions for non-agreed request data format

習慣沉默

After testing so far, it seems that angular's $http will automatically remove the content-type in the get request.

洪涛

Get parameters in the body are not in line with restful design. They should be written in the url. If the backend does not support url parameters, you can propose and change the backend. Some backends support writing url parameters into the body, but the content type format is form. data

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template