Last active
December 5, 2019 11:30
-
-
Save iBaozi/6b4095d17c528f38cba67c41361151d5 to your computer and use it in GitHub Desktop.
curl
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 | |
if (count($argv) < 2) { | |
echo "Usage: php curl.php http://haoip.cn" . PHP_EOL; | |
exit; | |
} | |
$url=$argv[1]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_USERAGENT,'curl/7.29.0'); | |
$content = curl_exec($ch); | |
$info = curl_getinfo($ch); | |
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
$header = substr($content, 0, $headerSize); | |
$output = substr($content, $headerSize); | |
curl_close($ch); | |
echo "********** Content *************" . PHP_EOL . $output . PHP_EOL; | |
echo '********** Header *************'. PHP_EOL . $header . PHP_EOL; | |
echo "******** Information ***********".PHP_EOL; | |
var_export($info); | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment