gpt4 book ai didi

php - cURL JSON post 不工作并且没有显示错误 PHP 7

转载 作者:行者123 更新时间:2023-12-05 05:23:39 24 4
gpt4 key购买 nike

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

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

最佳答案

尝试像这样发送 json:

curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

关于php - cURL JSON post 不工作并且没有显示错误 PHP 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37142214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com