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!
迷茫2017-05-15 17:09:41
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
習慣沉默2017-05-15 17:09:41
After testing so far, it seems that angular's $http will automatically remove the content-type in the get request.
PHP中文网2017-05-15 17:09:41
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