P
P
pavlyk2017-07-27 20:12:30
PHP
pavlyk, 2017-07-27 20:12:30

How to properly connect via cUrl with a proxy?

It seems that the connection to api vk was temporarily banned, I'm trying to send a request through a proxy

<?php
        $str = 'https://api.vk.com/method/wall.get?.....';
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $str); 
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208');
        curl_setopt($curl, CURLOPT_PROXY, 'ip:port');
        curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'user:pwd');
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_FAILONERROR, true);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
        $json = curl_exec($curl);
        
        $curl_error_code = curl_errno($curl);
        $curl_error_desc = curl_error($curl);
        $curl_info = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ($curl_error_code > 0) {
            exit($curl_error_desc . ' (' . $curl_error_code . '); HTTP-код: ' . $curl_info);
        }    
        curl_close($curl);
         var_dump(json_decode($json));

Returns
Connection timed out after 10001 milliseconds (28); HTTP-код: 0

At the same time, the same code is successfully executed from another server, I don’t understand what the problem is, it’s like the proxy doesn’t work like that, or something else ... tell me where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Semyon Beloglazov, 2017-07-27
@Batlab

If I'm not mistaken, then different providers allow CURL options in different ways.
Most likely, CURL is disabled on this hosting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question