java端提供了一个restful api,GET method是返回一个json,我用postman测试时候一定要在header里带上content-type:application/json才能success,否则就报415 unsupported media type。
我这里有个疑问,这个GET请求不带任何参数,为什么还要设置这个content-type呢?
另外我用angular的$http.get去访问这个api,我配置在请求头里的content-type被自动清除了好像。请大家答疑解惑,谢谢了!
迷茫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