我正在尝试在安装了wamp的服务器上使用curl连接,但是我拒绝连接Failed to connect to centrala.ratt.ro port 47654: Connection refused
,但我不知道为什么。如果我在浏览器中访问该链接,则可以正常工作,而使用php curl则无法正常工作。这是我的代码:
$url = "http://centrala.ratt.ro:47654/webhook/coordonate.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_PORT, 47654);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode ($result));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0);
// This should be the default Content-type for POST requests
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
$rezult = curl_exec($ch);
echo $rezult;
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
curl_close($ch);
答案 0 :(得分:0)
看着https://gustavostraube.wordpress.com/2016/08/31/debugging-requests-with-curl/;
/*
* We're going to use the output buffer to store the debug info.
*/
ob_start();
$out = fopen('php://output', 'w');
$handler = curl_init($url);
/*
* Here we set the library verbosity and redirect the error output to the
* output buffer.
*/
curl_setopt($handler, CURLOPT_VERBOSE, true);
curl_setopt($handler, CURLOPT_STDERR, $out);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handler);
fclose($out);
/*
* Joining debug info and response body.
*/
$data = ob_get_clean();
$data .= PHP_EOL . $response . PHP_EOL;
echo $data;
查看/发布$ out的输出以确定下一步;如果可以的话,您应该尝试在命令提示符下使用'-vvv'选项运行curl以获取类似的输出。