cURL JSON帖子不起作用,并且没有显示PHP 7的错误


cURL JSON post not working and shows no error PHP 7

我有一个奇怪的错误,在这个错误中,我在PHP7中的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命令时,它不会在日志中显示任何插入请求
  • 我有一个用PHP5设置的服务器,奇怪的是它确实在那里工作。。只是不在我有PHP7的本地开发环境中,所以我不确定是PHP7造成了问题,还是我只是忘记配置了一些东西
  • 我的服务器和开发环境都在CentOS 6.7上

如有任何帮助,我们将不胜感激。

尝试发送如下json:

curl_setopt($curl, CURLOPT_POSTFIELDS, $content);