使用curl请求java接口,返回报错
array(5) {
["timestamp"]=>
string(19) "2021-11-10 11:20:26"
["status"]=>
int(415)
["error"]=>
string(22) "Unsupported Media Type"
["message"]=>
string(76) "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"
["path"]=>
string(21) "/base/searchDrugTaboo"
}
原因:curl请求时,设置的content-type不对或者未设置。
解决方案:
$headers = array("content-type: application/json; charset=UTF-8");
在curl请求中,header内加上content-type设置,参数请求是json格式。