Crhistian Ramirez Crhistian Ramirez - 1 year ago 113
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);

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download