Crhistian Ramirez Crhistian Ramirez - 7 months ago 32
PHP Question

How can I capture the response body from a curl GET?

My $output prints true, indicating the request was successful. How would I access the actual response body?

add_action( 'init', 'get_login_details');
function get_login_details(){
$curl = curl_init();
$auth_token = 'somerandomtoken';

curl_setopt($curl, CURLOPT_URL, "");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization: Bearer $auth_token'));

$output = curl_exec($curl);


Add curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) and your body will be saved to $output.