我在使用 PHP 和 Curl 将 XML 数据发布到 Shopify 时遇到问题。我有:
$xml = '<?xml version="1.0" encoding="UTF-8"?><variant><id type="integer">260293006</id><fulfillment-service>manual</fulfillment-service><inventory-management>shopify</inventory-management><inventory-policy>deny</inventory-policy><sku>s136</sku><inventory-quantity type="integer">48</inventory-quantity><price>17.95</price></variant>';
$url = 'https://' . $API_KEY . ':' . $PASSWORD . '@' . $STORE_URL . '/admin/variants/#260293006.xml';
我的代码是:
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($session, CURLOPT_MAXREDIRS, 3);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $xml);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8'));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
echo $response;
curl_close($session);
Shopify 页面返回的内容为:
<title>Shopify » Please Log In</title>
我想我可能遗漏了一些明显的东西。一旦我让这个功能工作,其他一切都应该很容易构建。非常感谢。