我有以下cURL命令:
curl -i -H "Accept: application/json" -H "Content-Type: application/json; charset=utf-8" -H "TC: 000000" -H "ST: 000000" -X POST -d '[{"Param1" : "Value1", "Param2" : "Value2"} ]' http://www.somesaasprovider.com/
当我在终端中运行它并且得到预期的输出时,它工作正常。
然而,当我尝试使用相同的命令但适应PHP时,我没有得到任何结果。
PHP版本如下所示:
error_reporting(E_ALL);
ini_set('display_errors', '1');
$ch = curl_init('http://www.somesaasprovider.com');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"Param1" : "Value1", "Param2" : "Value2"}]');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json; charset=utf-8',
'TC' => '000000',
'ST' => '000000')
);
$response = curl_exec($ch);
$response = json_decode($response);
print_r($response);
我做错了什么?
感谢。