PHP cURL请求未提供任何输出
我试图通过PHP curl来执行这个命令行curl命令,我在命令行中得到了完美的输出,但在尝试使用PHP时却不一样PHP cURL请求未提供任何输出,php,curl,Php,Curl,我试图通过PHP curl来执行这个命令行curl命令,我在命令行中得到了完美的输出,但在尝试使用PHP时却不一样 curl -d "text=terrible" http://text-processing.com/api/sentiment/ 尝试编写一个PHP cURL,但没有得到任何输出 $data = "text=terrible"; $ch = curl_init('http://text-processing.com/api/sentiment/');
curl -d "text=terrible" http://text-processing.com/api/sentiment/
尝试编写一个PHP cURL,但没有得到任何输出
$data = "text=terrible";
$ch = curl_init('http://text-processing.com/api/sentiment/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
echo "<pre>";
print_r($response);
echo "</pre>";
$data=“text=terrable”;
$ch=curl\u init('http://text-processing.com/api/sentiment/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,“POST”);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$response=curl\u exec($ch);
回声“;
打印(回复);
回声“;
我认为您这方面不支持curl。我试过你的代码,它运行正常
尝试启用curl,然后尝试
;extension=php\u curl.dll
希望这将有助于他们的API状态,他们需要在此处对post进行表单编码数据 节选 若要分析某些文本的情绪,请使用包含要分析的文本的表单编码数据向发送HTTP POST。您将获得一个带有2个属性的JSON对象响应: 要在带有curl的PHP中执行此操作,必须使用值
application/x-www-form-urlencoded
传递Content-Type
的标题
示范
$data=“text=terrable”;
$ch=curl\u init('http://text-processing.com/api/sentiment/');
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:application/x-www-form-urlencoded');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$response=curl\u exec($ch);
回声“;
打印(回复);
回声“;
如果是这种情况,他可能会出现PHP错误。正如@techie_28提到的,我在问题中指出的,我没有得到任何输出。也没有错误。在cUrl调用中使用CURLOPT\u VERBOSE
可以更好地监控。
$data = "text=terrible";
$ch = curl_init('http://text-processing.com/api/sentiment/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo "<pre>";
print_r($response);
echo "</pre>";