nikunj001's avatar

Laravel curl is not working in proxy

I am trying to run curl in my office environment. But unfortunately i am not able to get the data from curl.and When i use same code at my laptop it is working fine . i don't know where to set the proxy in laravel. please help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 likes
3 replies
lostdreamer_nl's avatar

Just set the proxy options in curl:

// if you have your proxy running on your own PC port 8888

curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
// if the proxy also uses auth
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);

nikunj001's avatar

@lostdreamer_nl

I have already tried this solution. can you help me out more

$ch = curl_init($url);
$url = "http://beamtic.com/Examples/http-post.php";
curl_setopt($ch, CURLOPT_PROXY, '128.0.0.3');
curl_setopt($ch, CURLOPT_PROXYPORT, '8080');

// Perform the request, and save content to $result
$result = curl_exec($ch);
echo $result;

nikunj001's avatar
nikunj001
OP
Best Answer
Level 2

Hey Friends i have got the solution for this problem . i just have to install composer GuzzleHttp and code will work smoothly.

$client = new \GuzzleHttp\Client();
                $request_data = $client->get($url);
                $response = $request_data->getBody()->getContents();
                $AstroList = iconv("ISO-8859-1","UTF-8",$response);
                $AstroList = json_decode((string) $AstroList, true);

Please or to participate in this conversation.