Get url via http-proxy in php+curl
Solution:
- function GetData($url, $proxy='', $vars=''){
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 5);
- if($vars!=''){
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
- }
- if($proxy!='')
- curl_setopt($ch, CURLOPT_PROXY, $proxy);
- $str=curl_exec($ch);
- curl_close($ch);
- return $str;
- }
How to use this:
- $url='http://site.com/some-url.php';
- $proxy='255.255.255.255:80';
- // post variables
- $vars='var1=1&var2=text';
- $txt=GetData($url, $proxy, $vars);
- echo $txt;
Tags: PHP, curl, php, proxy
The requested URL could not be retrieved
While trying to retrieve the URL: http://www.google.fr
The following error was encountered:
Unable to determine IP address from host name for www.google.fr
The dnsserver returned:
Refused: The name server refuses to perform the specified operation.
This means that:
The cache was not able to resolve the hostname presented in the URL.
Check if the address is correct.