【发布时间】:2016-05-29 22:54:03
【问题描述】:
我有这个进行 curl 调用的 PHP 代码:
$postData['api_user'] = 'username';
$postData['api_key'] = 'password!';
$ch = curl_init('https://api.example.com/send.json');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
我知道为了在 bash 中使用 json 进行 curl 调用,我必须这样做:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource
但是我很困惑如何将我的所有 php 代码传输到 bash curl 调用,我的意思是例如什么相当于 curl_setopt(),并像我一样将凭据作为数组传递http_build_query()
【问题讨论】:
-
为什么不把它保留为 PHP 并使用命令行 PHP 来运行它呢?
-
因为我想知道如何使用这些选项运行 curl 调用
标签: php json bash curl scripting