设置 OAuth 授权标头的正确方法?
我想为 url xyz.com 设置请求标头 在php中设置它是正确的方法吗?
header('Authorization: AuthSub token="xxxxxx"');
header('location:https://www.google.com/accounts/AuthSubRevokeToken');
我正在尝试为此 URL 设置标头以进行调用。但是 Authorization: AuthSub 标头不会显示在 FireFox NET 面板的请求标头部分中。它用于显示请求。
有什么想法吗? 谢谢。
我以前使用过curl,但它似乎没有发出任何请求,因为我在FireFox的NET面板中看不到它。 代码如下:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"https://www.google.com/accounts/AuthSubRevokeToken");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="1/xxx"'
));
$result = curl_exec($curl);
curl_close($curl);
echo 'hererer'.$result;exit;
I want to set a request header for a url xyz.com
is it the right way to set it in php?
header('Authorization: AuthSub token="xxxxxx"');
header('location:https://www.google.com/accounts/AuthSubRevokeToken');
I am trying to set the header for this URL for a call.But the Authorization: AuthSub header doesnt shows up in the request headers section of the FireFox NET panel.Which is used to show the requests.
Any idea about it?
Thanx.
I was using curl previously,But it didnt seemed to issue any request as i cant see it in the NET panel of FireFox.
Code is as follows:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"https://www.google.com/accounts/AuthSubRevokeToken");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="1/xxx"'
));
$result = curl_exec($curl);
curl_close($curl);
echo 'hererer'.$result;exit;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
header
设置响应标头,而不是请求标头。 (如果您尝试在其他地方发送 HTTP 请求,则不会有任何效果。)另请注意手册中关于
记住在发送任何实际输出之前必须调用 header() 的内容,....
在使用
header()
之前打开error_reporting(E_ALL);
看看这是否是您的问题。header
sets response headers, not request headers. (If you were trying to send a HTTP request elsewhere, it would have no effect.)Please also note what the manual says about
Remember that header() must be called before any actual output is sent, ...
.And turn on
error_reporting(E_ALL);
before usingheader()
to see if that is the issue for you.标头名称和值需要用一个冒号加一个空格分隔,因此“标头”的位置是错误的,它应该是:(
写法也很常见,但不是必需的)
这种
header
函数设置的是响应头,而不是请求头。所以你基本上使用了错误的工具。在 PHP 中,您无法设置请求标头,这是客户端(例如浏览器)的一部分,而不是服务器的一部分。所以
header
在这里看起来是错误的。您使用哪个 HTTP 客户端?Header names and values need to be separated by one colon plus a space, so the location "header" is just wrong, it should be:
(It's common to write the case this way, too, but not a need)
Next to that the
header
function is setting response headers, not request headers. So you're basically using the wrong tool.In PHP you can not set request headers, that's part of the client (e.g. browser), not the server. So
header
just looks wrong here. Which HTTP client are you using?调用,如使用 CURL 请求另一个页面? header() 函数仅适用于网络浏览器<->服务器通信。它不会影响您的服务器端脚本对其他网络服务器发出的任何请求。为此,您需要修改正在使用的特定方法,例如curl 或stream。
对于curl,请参见此处的
CURLOPT_HTTPHEADER
:http://php.net/curl_setoptA call, as in using CURL to request another page? The header() function applies only for web-browser<->server communications. It cannot affect any requests your server-side script does to other webservers. For that, you need to modify the particular method you're using, e.g. curl or streams.
For curl, see
CURLOPT_HTTPHEADER
here: http://php.net/curl_setopt