Curl With Get Method in PHP

Curl With Get Method in PHP

 $url = 'https://www.postsparrow.com/api?per1=123&language=EN';
        $header = array(
            'Content-Type: application/json'
        );

        $curl_arr = curl_init($url);
	curl_setopt($curl_arr, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl_arr, CURLOPT_MAXREDIRS, 10);
	curl_setopt($curl_arr, CURLOPT_POST, true);
	curl_setopt($curl_arr, CURLOPT_CUSTOMREQUEST, "GET");
	curl_setopt($curl_arr, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($curl_arr, CURLOPT_HTTPHEADER, $header);
	$buffer = curl_exec($curl_arr);
	curl_close($curl_arr);

	$response = json_decode($buffer);

          echo "<pre>";print_r($response);die();

if You want to Add Basic Authorization then header

$header = array(
        'Content-Type: application/json',
        'Authorization: Basic '. base64_encode("admin:12345")
    );

0 Comments

Leave a Reply

You must be logged in to post a comment.