...PHPでPOSTリクエスト後にHTTPレスポンスヘッダを取得するには?
私はIIS7 の下にPHP 5を持って、私はPOSTを使用したコードは次のようになります -
$url="http://www.google.com/accounts/ClientLogin"; $postdata = http_build_query( array( 'accountType' => 'GOOGLE', 'Email' => '[email protected]', 'Passwd' => 'xxxxxx', 'service' => 'fusiontables', 'source' => 'fusiontables query' ) ); $opts = array('http' => array( 'header' => 'Content-type: application/x-www-form-urlencoded', 'method' => 'POST', 'content' => $postdata ) ); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context);
以上、単純なClientLogin認証をGoogleに行って、ヘッダーに返すAuthトークンを取得したいとします。 $ resultをエコーすると、本文の内容だけが返され、認証トークンのデータを含むヘッダーは返されません。
あなたの例でレスポンスヘッダを持つことができないと思います(file_get_contentsはレスポンスボディを返します) – Andreas
php5のget_headers()は何をしますか? (sinanは下で回答しました)または、php5を使用してGoogle ClienLoginから認証トークンを取得するための回避策をお勧めしますか? – Irfan