卷曲连接拒绝端口80和443

时间:2018-04-09 13:24:27

标签: php curl

我有一个我推断出的函数特别是curl_exec失败了。 我从curl得到的错误响应是

    Failed to connect to www.domain.co.za port 80(and same for 443): Connection refused 

这是我的功能

奇怪的是,这种情况在昨天稳定了几个月后才停止工作

有人能指出我为什么会失败的正确方向吗?

它进入的网址是正确的,如果输入浏览器

,则有效
    private function post_to_callback($url, $fields) {
        unset($fields->raw);
        //url-ify the data for the POST
        $fields_string = http_build_query($fields);
        //mail('anthony@domain.co.za','debug',$fields_string);
        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        // $count = 1;
        // $url = str_replace("https://", "http://", $url, $count);
        curl_setopt($ch,CURLOPT_URL, $url);

        //tried this and it didnt work
        curl_setopt( $ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

        curl_setopt($ch,CURLOPT_POST, count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);


    $result = curl_exec($ch);
    if(curl_errno($ch)){
        echo 'Curl error: ' . curl_error($ch);

        mail('anthony@domain.co.za','curl error','<pre>'. curl_error($ch) .'</pre>');
    }

    //echo $result;

    //close connection
    curl_close($ch);
}

编辑:这是它尝试卷曲的脚本

<?php
mail('anthony@domain.co.za','debug','it got to the beginning of callback');
$name = filter_input(INPUT_POST, 'full_name');
$email = filter_input(INPUT_POST, 'email');
$number = '0' . substr(str_replace('+', '', filter_input(INPUT_POST, 'phone_number')), -9);

mail('anthony@d9omain.co.za','debug','it got to the campaign');

$campaign = "Herbal Peel - Parkhurst - April 2018";
$friendly = "Herbal%20Peel%20Special";
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "Last signup " . date('Y-m-d H:i:s');
fwrite($myfile, $txt);
foreach($_POST as $k => $p) {
fwrite($myfile, "$k => $p \r\n");
}
fwrite($myfile, "$name $email $number $campaign");

// Connect to foreign MySQL database
$link = mysqli_connect('localhost', 'db', 'db', 'db');
$query = "INSERT INTO cosmag_leads (campaign, name, number, email, date,friendly_name) VALUES ('$campaign', '$name', '$number', '$email', NOW(),'$friendly');";
mail('anthony@domain.co.za','debug',$query);
fwrite($myfile, $query);
mysqli_query($link, $query);
mysqli_close($link);

0 个答案:

没有答案