Jump to content

PHP CURL proxy question


imparator

Recommended Posts

Is there any way I can use curl through a proxy without specifying my username and password in the actual script?

 

My code is as follows:

 

$URL ='http://www.asx.com.au/asx/markets/EquitySearchResults.jsp?method=get&template=F1001&ASXCodes=BHP%20NAB%20CBA'; 
//Initialize the Curl session
$ch = curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "xxxxxx.xx.xxx.xxx.xx");
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "user:pass");
//Set the URL
curl_setopt($ch, CURLOPT_URL, $URL);
//Execute the fetch
$data = curl_exec($ch) or die(curl_error($ch));
//Close the connection
curl_close($ch);
print $data;

 

which works fine, but when i remove the username and password I get an Access denied due to authentication failure. even though I have the proxy setup in .curlrc with the appropriate details.

 

Not: I know the proxy is set properly in .curlrc because I can type:

curl http://www.whateversite.com in the commandline

and it works fine

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/44722-php-curl-proxy-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.