Skip to content

Instantly share code, notes, and snippets.

@pepebe
Forked from hubgit/curl-verbose.php
Created January 13, 2020 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepebe/1ef45ec3bbb93143f82dec550c6c2e1c to your computer and use it in GitHub Desktop.
Save pepebe/1ef45ec3bbb93143f82dec550c6c2e1c to your computer and use it in GitHub Desktop.
Verbose cURL in PHP
<?php
// Request URL
$url = 'http://www.google.com/';
// HTTP headers
$headers = array(
//'Content-Type: application/json',
//'Accept: application/json',
);
// Content to send. If a Content-Type header is not specified when sent as POST data, the Content-Type will be set to 'application/x-www-form-urlencoded' and this should be an array; otherwise it can be a string.
//$content = json_encode($documents);
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
//CURLOPT_POSTFIELDS => $content, // sets the method to POST automatically
));
$response = curl_exec($curl);
print_r($response);
//print_r(json_decode($response));
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
print_r($code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment