如何在PHP中的POST请求后获取HTTP响应头? [英] How to get HTTP response headers after POST request in PHP?
问题描述
我想知道在PHP中的POST请求之后是否可以在不使用cURL的情况下读取/解析HTTP响应头。
I want to know if it's possible to read/parse the HTTP response header after a POST request in PHP without the use of cURL..
我有PHP 5在IIS7
下我用来POST的代码是: -
I have PHP 5 under IIS7 The code I use to POST is :-
$url="http://www.google.com/accounts/ClientLogin";
$postdata = http_build_query(
array(
'accountType' => 'GOOGLE',
'Email' => 'xxxxx@gmail.com',
'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身份验证,我想要获取在标头中返回的Auth令牌。回显$ result只给出正文内容,而不是包含auth令牌数据的标题。
Above, im doing a simple ClientLogin Authentication to google and I want to get the Auth token which returns in the header. Echo-ing $result only gives the body content and not headers which contains the auth token data.
推荐答案
函数get_headers()可能是你正在寻找的那个。
The function get_headers() may be the one you are looking for.
http:// php.net/manual/en/function.get-headers.php
这篇关于如何在PHP中的POST请求后获取HTTP响应头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!