duanguangwang5829 2019-04-01 02:16 采纳率: 0%
浏览 138

curl连接失败连接失败

i'm trying to connect with curl on a server that has wamp installed but i get connection refused Failed to connect to centrala.ratt.ro port 47654: Connection refusedand i don't know why. If i access the link in browser it works, with php curl it's not working. Here is my code:

$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);
  • 写回答

2条回答

  • dsgtew3241 2019-04-01 02:43
    关注

    Looked at 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;
    

    Review / post the output for $out to determine next steps; If you can, you should attempt to run curl on the command prompt with the '-vvv' options to get similar output.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料