Normal proxies (ex: 72.41.132.22:3128) work well with cURL, however when I use SOCKS 5 proxies with username/pass, It just gives me "[1" on the page.
Is there a way to use SOCKY 5 proxies with cURL ?
$proxy = "cagsan:jw22wdw#108.61.25.223:34792";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
You need to tell cURL the proxy is a SOCKS5 proxy, otherwise cURL assumes it's an HTTP proxy:
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
From the docs:
CURLOPT_PROXYTYPE
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
since cURL 7.21.7, you can use CURLOPT_PROXY and specify the SOCKS protocol:
curl_setopt($ch, CURLOPT_PROXY, 'socks5://bob:marley#localhost:12345');
More informations in the libcurl documentation.
For those looking to connect via a hostname(localhost?), and it's not working with CURLPROXY_SOCKS5, you can try CURLPROXY_SOCKS5_HOSTNAME.
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
In some earlier PHP versions, you will have to do:
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
Related
hi im trying to use proxy (http protocol) in curl to connect to websites that use https, but no luck it return : Received HTTP code 400 from proxy after CONNECT
i tried to add the flowing : ,
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL, true);
here is my code :
$proxy_ip = //proxy ip;
$proxy_port = //proxy port;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com');\\ example
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
echo curl_error($ch);
echo $result;
the proxy works fine on postman so i know for sure that the proxy that im using is live
and it don't need authentication
I am trying to use curl through a proxy, when I dont use a proxy it works fine but if I use a proxy it returns null, no error messages or anything.
I have already tried other opened questions but their answers are inconclusive.
Here is my code:
<?php
$url = 'http://dynupdate.no-ip.com/ip.php';
$proxy = '122.117.225.161:8080';
//$proxyauth = 'user:pass';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
var_dump($curl_scraped_page);
?>
The proxy there is a free working proxy (I manually checked), I have also tried it with a private proxy (I used the user:pass authentication method) but still returns null.
Any information will be helpful.
Thanks!
Modern browsers support HTTPS proxies that can be connected to via a PAC file (see https://www.igvita.com/2012/06/25/spdy-and-secure-proxy-support-in-google-chrome/ if you're not familiar).
I'm trying to replicate the same thing and connect to such a proxy via php CURL, but I'm simply getting a blank response, no headers or content.
My code is as follows:
$url = "http://checkip.dyndns.com";
$proxy = "proxy.domain.com:443";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL , 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'test:test');
curl_setopt($ch, CURLOPT_PROXYTYPE, "CURLPROXY_HTTP");
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Any ideas?
If anyone is interested, the solution to this is to use spdycat instead of curl: https://github.com/tatsuhiro-t/spdylay
There's no support for connecting to a proxy with HTTPS with curl yet. There is a work-in-progress branch in git though: https://github.com/bagder/curl/tree/HTTPS-proxy
We will appreciate help to get that in shape to merge.
Code:
$url = 'example/'.$reqID.'/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
//var_dump($output);
curl_close($ch);
Error:
curl_setopt() [function.curl-setopt]: Invalid curl configuration option
the error can indicate that you try to use curl in an IPv6 enabled environment and don't tell curl to resolve over IPv4
try to set the option
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
Allows an application to select what kind of IP addresses to use when
resolving host names. This is only interesting when using host names
that resolve addresses using more than one version of IP, possible
values are CURL_IPRESOLVE_WHATEVER, CURL_IPRESOLVE_V4,
CURL_IPRESOLVE_V6, by default CURL_IPRESOLVE_WHATEVER.
I have problem with scraping data over proxy which use authentication. Proxy is online, its private and it work very fast from browser.
However proxy requires authentication and i just cant think of why this simple script doesnt work?!
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://automation.whatismyip.com/n09230945.asp");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_PROXY, "proxyIP:proxyPORT");
curl_setopt($ch, CURLOPT_PROXYUSERPWD,"username:password");
$result = curl_exec($ch);
curl_close($ch);
return $result;
?>
I have tried to set CURLOPT_HTTPAUTH with any valid value and it is same.. Any suggestion?
Try setting:
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
You need to use CURLOPT_PROXYTYPE to tell curl which type of proxy you're using, as it will otherwise assume default type which is HTTP...
Try this :
curl_setopt($ch, CURLOPT_PROXY, 'proxyIP');
curl_setopt($ch, CURLOPT_PROXYPORT, 'proxyPORT');
instead of this :
curl_setopt($ch, CURLOPT_PROXY, "proxyIP:proxyPORT");