最終更新:2012-04-06 (金) 15:00:24 (4396d)  

PEAR/HTTP_Client
Top / PEAR / HTTP_Client

GET

require_once ( "HTTP/Client.php" );

$http_client = new HTTP_Client();
$result = $http_client->get( $url );
if ( !PEAR::isError( $result ) ) {
    header( 'Content-Type: text/plain; charset=UTF-8' );
    echo "通信に成功しました\n\n"
    $http_response = $http_client->currentResponse();
    if ( '200' == $http_response['code'] ) {
        echo "データ取得に成功しました\n\n";
        echo mb_convert_encoding( $http_response['body'], "UTF-8", "auto" );
    } else if ( '302' == $http_response['code'] ) {
        echo "指定されたURLは以下のURLにリダイレクトされています\n";
        echo $http_response['headers']['location'] . "\n";
    } else if ( '404' == $http_response['code'] ) {
        echo "指定されたURLにファイルがありませんでした\n";
    }
}

POST

require_once ( "HTTP/Client.php" );

$client = new HTTP_Client();

$loginUrl="http://www.tumblr.com/login";
$loginParams = array(
    'email' => 'hoge@example.com',
    'password' => 'hoge',
    'redirect_to'=>'/dashboard',
);

$client->post($loginUrl, $loginParams); 
$response = $client->currentResponse(); 

関連

後継