cURL-JSON-post不工作,并且没有显示错误PHP7

cURL-JSON-post不工作,并且没有显示错误PHP7,php,json,curl,php-7,Php,Json,Curl,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: appl

我有一个奇怪的错误,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模块确实可以工作,因为我能够从其他来源发布和获取查询
  • localhost:7369上的程序正在运行和工作。执行cURL命令时,它不会在日志中显示任何输入请求
  • 我有一个用PHP5设置的服务器,奇怪的是它确实在那里工作。只是在我有PHP7的本地开发环境中没有,所以我不确定PHP7是不是导致了问题,或者我只是忘记了配置一些东西
  • 我的服务器和开发环境都在CentOS 6.7上

任何帮助都将不胜感激

尝试发送json,如下所示:

curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

你查过phpinfo了吗?您的服务器上安装了curl吗?如果没有,那么您可以通过sudo安装apt-get-install php5-curl-moduleThanks,但正如我所说的,我有PHP7,所以如果我没记错的话,我是通过yum安装php70w-common的。默认情况下,cURL包包含在该包中。我能够在cURL中做一些事情(简单的POST-and-GET),但不知为什么我上面的脚本不起作用。请参阅禁用您的iptables或任何防火墙,然后重试。请尝试使用telnet localhost 7369从您的开发环境连接到您的服务,并确保您能够连接。如果telnet正在工作,您可以作为下一步进行检查。这可能会有帮助。