今天和大數據組對一個接口,請求他們的接口 報錯: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,還有裏面是雙引號哦。