Fork me on GitHub

标签 curl 下的文章

PHP的Curl类

经常会用到PHP cURL 模拟一些http请求,每次都写一大段很不方便,

所以在github上找到一个PHP Curl类,https://github.com/php-curl-class/php-curl-class

文档地址:http://www.crarun.com/docs/curl/curl.html

Quick Start and Examples

require 'Curl.php';
use CurlCurl;
 
//GET请求
$curl = new Curl();
$curl->get('
 
//POST请求
$curl = new Curl();
$curl->post('http://www.example.com/login/', array(
    'username' => 'myusername',
    'password' => 'mypassword',));
 
//带参数
$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('');$curl->setReferrer('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get(' 
if ($curl->error) {
    echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
}else {
    echo $curl->response;
}
var_dump($curl->request_headers);
var_dump($curl->response_headers);