php - 如何从此文档制作 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
}'
解决方案
$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);
推荐阅读
- powershell - Chrome 命令行标志什么都不做
- javascript - React 和 onClick 在 div 或 span 中以及可能的缺点
- javascript - 找不到路线
- maven - 如何在使用 native-maven 插件创建 JNI .so 后运行 JUnit 测试
- git - 将项目分支合并到演示分支的正确程序
- html - Bootstrap 4:内联表单按钮高度
- excel - 如何使用 selenium+chrome+vba 在 trello 上单击板?
- c++ - 如何使用原语和 Eigen 创建尾随返回类型?
- javascript - 基于同一对象中另一个值的最大值/最小值的返回值
- here-api - 如何在一张地图上显示多个地址