在PHP中执行Curl语句

奥米肯人

我在bigcommerce中工作,我需要做一些事情,Bigcommerce为此提供了curl格式的代码...我不太了解curl ...您能告诉我如何在php中执行以下代码吗?

curl --request POST \
-u "admin:key" \
-H "Content-Type: application/json" \
-d '{"order_address_id":15,"tracking_number":"123-123-123","items":[{"order_product_id":15,"quantity":1}]}' \
https://store/api/v2/orders/114/shipments.json

任何帮助将不胜感激...

巴尔玛
$ch = curl_init('https://store/api/v2/orders/114/shipments.json');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, 'admin:key');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, 
    json_encode(array('order_address_id' => 15,
                      'tracking_number' => '123-123-123',
                      'items' => array(
                            array('order_product_id' => 15, 'quantity' => 1)
                        )
                     )));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章