Created
December 2, 2011 16:40
-
-
Save hubgit/1423886 to your computer and use it in GitHub Desktop.
Verbose cURL in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This snippet has been really helpful lately as I've been producing evidence of TLS 1.2 compatibility and CA support of some legacy stuff. Thanks.