我遇到了一个奇怪的错误,在我的PHP 7 cURL脚本中似乎无法正常工作,也没有报错。我的代码:
$content = json_encode(array(
'I was just testing',
'Whether or not this is working',
));
$collatex_url = 'http://localhost:7369/collate';
$collatex_headers = array(
"Content-type: application/json; charset=UTF-8;",
"Content-Length: " . strlen($content),
"Accept: application/json"
);
$curl = curl_init($collatex_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $collatex_headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array('json' => $content));
//curl_setopt($curl, CURLOPT_POSTFIELDS, array('json=' . urlencode($content))); //tried, also does not work
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
echo curl_error($curl); //does not produce an error
echo 'THE RESULT IS' . $result; //the result is empty
curl_close($curl);
- 我的Selinux已经设置成宽容模式。
- 我的cURL模块能够工作,因为我已经可以从其他来源进行POST和GET查询。
- 在localhost:7369上运行的程序正在工作。执行cURL命令时,它的日志中没有显示任何传入请求。
- 我有一个安装了PHP 5的服务器,奇怪的是它可以正常运行,但是在我的本地开发环境中却不能正常运行。我使用的是PHP 7,因此我不确定是PHP 7引起了问题,还是我忘记配置了某些内容。
- 我的服务器和开发环境都是在CentOS 6.7上。
非常感谢您的帮助。