用PHP购买XML Post
发布时间:2020-12-13 17:43:21 所属栏目:PHP教程 来源:网络整理
导读:我在使用 PHP和Curl to Shopify发布XML数据时遇到问题.我有: $xml = '?xml version="1.0" encoding="UTF-8"?variantid type="integer"260293006/idfulfillment-servicemanual/fulfillment-serviceinventory-managementshopify/inventory-managementinventor
我在使用
PHP和Curl to Shopify发布XML数据时遇到问题.我有:
$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,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,true); $response = curl_exec($session); echo $response; curl_close($session); Shopify页面返回的是什么: <title>Shopify » Please Log In</title> 我想我可能错过了一些明显的东西.一旦我使这个功能工作,其他一切都应该很容易构建.非常感谢. 解决方法
感谢大家.根据这些反馈,我能够解决问题.大部分问题:
>用户-457786建议不需要# $fp = tmpfile(); fwrite($fp,$xml); fseek($fp,0); $session = curl_init(); curl_setopt($session,CURLOPT_PUT,CURLOPT_BINARYTRANSFER,CURLOPT_INFILE,$fp); // file pointer curl_setopt($session,CURLOPT_INFILESIZE,strlen($xml)); curl_setopt($session,array('Content-Type: application/xml')); $response = curl_exec($session); fclose($fp); curl_close($session); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |