我有一个奇怪的错误,其中我的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);
任何帮助将不胜感激。
答案 0 :(得分:2)
尝试像这样发送json:
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);