首页 > 解决方案 > 如何从此文档制作 php cURL

问题描述

如何从此文档制作 PHP cURL,下面是 curl 原始文本

curl --location --request POST '/serviceRates' \
    --header 'Content-Type: application/json' \
    --header 'access-key-id: ***' \
    --header 'secret-access-key: ***' \
    --data-raw '{
        "origin": "31.72.01",
        "destination": "31.72.55",
        "weight": 2000
    }'

标签: phpjsoncurl

解决方案


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, '/serviceRates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Access-Key-Id: ***';
$headers[] = 'Secret-Access-Key: ***';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

推荐阅读