今天和大数据组对一个接口,请求他们的接口 报错:status":415,"error":"Unsupported Media Type","message":"Content type 'multipart/form-data;
然后在头部加入
$curl->setHeader(array("Content-Type"=>"application/json"));
这个报错算是解决了。
接着又来一个报错:
JSON parse error: Unexpected character ('-' (code 45)) in numeric value....
试了半天,把参数的数据加上json_encode解决:
$curl->post($url, json_encode(array("dimensionType"=>"energy","dimension"=>"new_energy","sortDimension"=>"brand_id","periodType"=>"week"));
头部知道了application/json, 那么参数就必须是json格式,一定要加json_encode,还有里面是双引号哦。