post to a remote server using cURL from a server using proxy/firewall

I am developing a wordpress plugin which post data to a remote server using cURL.
This works fine on maximum websites but on some websites it just come up with an ERROR ACCESS DENIED.

    [headers] => Array
    (
        [server] => squid/3.3.8
        [mime-version] => 1.0
        [date] => Tue, 31 Mar 2015 07:32:51 GMT
        [content-type] => text/html
        [content-length] => 3406
        [x-squid-error] => ERR_ACCESS_DENIED 0
        [vary] => Accept-Language
        [content-language] => en
        [x-cache] => MISS from hproxy2.world4you.com
        [x-cache-lookup] => NONE from hproxy2.world4you.com:3128
        [via] => 1.1 hproxy2.world4you.com (squid/3.3.8)
        [connection] => close
    )

Above is the response which I am geting.

Read More

Below is the code which I am using

    function testpost($ac,$d_name,$an,$data) {
        $fields = '';
        foreach ($data as $key => $value) {
            $fields .= $key . '=' . $value . '&';
        }

        rtrim($fields, '&');
    $post = curl_init();
    curl_setopt($post, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($post, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($post, CURLOPT_URL, $ac);
    curl_setopt($post, CURLOPT_POST, count($data));
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 2);
    $result = curl_exec($post);
    echo "<pre>";
    print_r($result);
    echo "</pre>";      

}

Also, on some server it keep executing and not return anything. For these not able to figuring out what’s the issue and even not able to show user some error message because it does not return anything.

e.g.
If I install the plugin on abc.com and try to POST using cURL to xyz.com/test.php, in test.php I have written the code to wirte data into text file to check the cURL request from abc.com is reaching on xyz.com or not. But it does not write anything into text file means request is not reaching from abc.com to xyz.com. In this I does not get any response and it keep executing on abc.com for a long time.

So, I need help in finding out what’s creating this problem and how I can POST data from abc.com to xyz.com

Related posts

Leave a Reply

2 comments

  1. The Websites or Server where you are running your plugin is behind a firewall and hence it is blocking your cURL request. To overcome this user’s of this plugin has to pass their server proxy setting.
    See below-

        function testpost($ac,$d_name,$an,$data,$proxy_ip,$proxy_port,$login_passw) {
        $fields = '';
        foreach ($data as $key => $value) {
            $fields .= $key . '=' . $value . '&';
        }
    
        rtrim($fields, '&');
    $post = curl_init();
    curl_setopt($post, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($post, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($post, CURLOPT_URL, $ac);
    curl_setopt($post, CURLOPT_POST, count($data));
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($post, CURLOPT_PROXYPORT, $proxy_port);
    curl_setopt($post, CURLOPT_PROXYTYPE, 'HTTP');
    curl_setopt($post, CURLOPT_PROXY, $proxy_ip);
    curl_setopt($post, CURLOPT_PROXYUSERPWD, $login_passw);
    $result = curl_exec($post);
    echo "<pre>";
    print_r($result);
    echo "</pre>";      
    

    }