A
A
Alex Alex2015-12-07 08:14:06
PHP
Alex Alex, 2015-12-07 08:14:06

How to work with proxy in cUrl?

How to use http/s socks in cUrl?
Links are not interesting, specific examples of use are interesting.
I'm trying to send a request from an http proxy with authorization, the response is "empty"

<?php
function get($url) {
$ch=curl_init(); 
curl_setopt($ch, CURLOPT_URL, trim($url)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
curl_setopt($ch, CURLOPT_PROXY, '30.148.96.136:55575');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'INST0012:DoJeg5');
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208'); 
$res=curl_exec($ch); 
curl_close($ch);
return $res;
} 

$buf = get('https://www.instagram.com/petukhov_serega/');
echo $buf;
echo 'Пусто';

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Muhammad, 2015-12-07
@muhammad_97

Try like this:

if(curl_exec($ch) === false) {
    return 'Ошибка: ' . curl_error($ch);
}

Most likely a problem with HTTPS. Try disabling validation:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

Another option is to get an SSL certificate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question