php curl
0.8.1
{
"require" : {
"sylouuu/php-curl" : "0.8.*"
}
} require_once ' ./vendor/autoload.php ' ; // Namespace shortcut
use sylouuu Curl Method as Curl ;
// Template
$ request = new Curl < METHOD_NAME >( string $ url [, array $ options ] );방법은 다음과 같습니다.
Get()Head()Options()Post()Put()Patch()Delete()$options [
' data ' => [ // Data to send, available for `Post`, `Put` and `Patch`
' foo ' => ' bar '
],
' headers ' => [ // Additional headers (optional)
' Authorization: foobar '
],
' ssl ' => ' /cacert.pem ' , // Use it for SSL (optional)
' is_payload ' => true , // `true` for sending a payload (JSON-encoded data, optional)
' autoclose ' => true // Is the request must be automatically closed (optional)
] // Send a request
$ request -> send ();
// HTTP status code
$ request -> getStatus ();
// HTTP header
$ request -> getHeader ();
// HTTP body response
$ request -> getResponse ();
// Used cURL options
$ request -> getCurlOptions ();
// Set a cURL option
$ request -> setCurlOption ( CURLOPT_SOMETHING , $ value );
// Manually close the handle (necessary when `autoclose => false` is used)
$ request -> close ();기초적인:
// Namespace shortcut
use sylouuu Curl Method as Curl ;
// Standard GET request
$ request = new Curl Get ( ' http://domain.com ' );
// Send this request
$ request -> send ();
echo $ request -> getResponse (); // body response
echo $ request -> getStatus (); // HTTP status code페이로드 보내기 :
// Namespace shortcut
use sylouuu Curl Method as Curl ;
// JSON-encoded POST request
$ request = new Curl Post ( $ this -> endpoint , [
' data ' => [
' name ' => ' foo ' ,
' email ' => ' [email protected] '
],
// With 'is_payload' => true
// You don't have to json_encode() your array of data
// Moreover, the appropriate headers will be set for you
' is_payload ' => true
]);
// Send this request
$ request -> send ();
echo $ request -> getResponse (); // body response
echo $ request -> getStatus (); // HTTP status code수동 폐쇄 :
// Namespace shortcut
use sylouuu Curl Method as Curl ;
// Set `autoclose` option to `false`
$ request = new Curl Get ( ' http://domain.com ' , [
' autoclose ' => false
]);
// Send this request
$ request -> send ();
// Now you can retrieve a cURL info as the handle is still open
$ request -> getCurlInfo ( CURLINFO_SOMETHING );
echo $ request -> getResponse ();
// Manually close the handle
$ request -> close ();프로젝트 디렉토리 :
composer install phpunit 검색하기 위해 설치합니다phpunit 2015-08-25-0.8.1
2015-07-03-0.8.0
is_payload 옵션 추가ssl 옵션2014-10-23-0.7.1
Post()2014-08-01-0.7.0 (BC Break)
Method 디렉토리가 추가 된 다음 메소드가 sylouuuCurlMethod 에 있습니다.2014-05-30-0.6.1
Post Put 및 Patch 에 data 옵션이 지정되지 않은 경우 예외 제거2014-05-22-0.6.0 (BC Break)
url 옵션을 첫 번째 생성자 매개 변수로 이동했습니다2014-05-20-0.5.0 (BC Break)
php-rest-client 에서 php-curl 로 이름이 바뀌 었습니다autoclose 옵션이 추가되었습니다2014-05-13-0.4.0 (BC Break)
RESTClient.class.php 로 이름을 RESTClient.php 로 변경했습니다RESTClient.php /src 로 이동했습니다RESTClientTest.php /tests 로 이동했습니다HEAD , OPTIONS 및 PATCH 지원이 추가되었습니다getHeader 방법이 추가되었습니다getJSON 으로 이름을 getResponse 로 변경했습니다sylouuu 네임 스페이스가 추가되었습니다gulp 제거2014-05-09-0.3.0
ssl 옵션이 추가되었습니다2014-04-06-0.2.1
2014-04-04-0.2.0
2014-04-01-0.1.0
2014-03-24-0.0.2
$api_url 생성자 매개 변수로 추가했습니다2014-02-05-0.0.1