curl连接失败连接失败

问题描述 投票:0回答:1

我正在尝试连接与已安装wamp的服务器上的curl但我得到连接被拒绝Failed to connect to centrala.ratt.ro port 47654: Connection refusedand我不知道为什么。如果我访问浏览器中的链接它是有效的,使用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);
php curl server wamp
1个回答
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以获得类似的输出。

© www.soinside.com 2019 - 2024. All rights reserved.