2
我一直在嘗試使用JSON調用中文網站API一個多星期,但它不工作。 與我應該叫參數的網址是:PHP和cURL的JSON調用
http://gw.api.jd.com/routerjson?v=2.0&method=jingdong.ware.product.search.list.get&app_key=XXXXXXXX&360buy_param_json={"isLoadAverageScore":"TRUE","isLoadPromotion":"TRUE","sort":"1","page":"1","pageSize":"10","keyword":"裇衫","client":"apple"}×tamp=2015-05-07 07:28:14&sign=ZZZZZZZZ
下面的代碼是不工作
$data = array("360buy_param_json" => array("isLoadAverageScore" => "TRUE", "isLoadPromotion" => "TRUE", "sort" => "1", "page" => "1", "pageSize" => "10", "keyword" => "'.$this->searchTerm.'", "client" => "apple"));
$data_string = json_encode($data);
$ch = curl_init('http://gw.api.jd.com/routerjson?v=2.0&method=jingdong.ware.product.search.list.get&app_key=XXXXXXXX×tamp='.$TimeInChina.'&sign=ZZZZZZZZZ');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
我也試過幾個變化,像周圍的360buy_param_json場,但沒有移動似乎工作。
$data = array("isLoadAverageScore" => "TRUE", "isLoadPromotion" => "TRUE", "sort" => "1", "page" => "1", "pageSize" => "10", "keyword" => "'.$this->searchTerm.'", "client" => "apple") ;
$data_string = '&360buy_param_json='.json_encode($data).'';
任何想法如何使這隻小狗工作?謝謝 和平
爲什麼你把JSON放在post字段中,當它應該是一個URL參數? – Barmar
因爲我不知道我在做什麼。非常感謝你! –