想知道为什么此代码不会更新我的产品。我在chrome休息控制台上测试过,效果很好。但是,在php中测试curl时它不会更新。我已经测试过在php中使用curl做一个简单的GET请求产品计数,它反应很好。只是PUT给了我适合。有什么突出的吗?
<?php
$baseUrl = https://apikey:password@hostname/admin/';
$variant =
array('inventory_quantity' => 20
);
$ch = curl_init($baseUrl.'variants/19175889219.json'); //note product ID in url
$data_string = json_encode(array('variant'=>$variant)); //json encode the product array
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //specify the PUT verb for update
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); //add the data string for the request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //set return as string true
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
); //set the header as JSON
$server_output = curl_exec ($ch); //execute and store server output
curl_close ($ch); //close the connection
echo $data_string;
echo $server_output;
?>