大网数据广告活动
网站运营与故障问答

POSTing authorization headers with no $_SERVER['HTTP_AUTHORIZATION'] and no 'authorization' value in apache_request_headers()

· 52CE 我爱测

I'm developing a web application that interacts with a GraphQL instance on another server (not mine). The GraphQL instance requires me to send an authorization header ("Bearer [token]"). The responses I'm getting from GraphQL see…

问题原文

原帖链接 · Eye Teeth · CC BY-SA 4.0

I'm developing a web application that interacts with a GraphQL instance on another server (not mine). The GraphQL instance requires me to send an authorization header ("Bearer [token]"). The responses I'm getting from GraphQL seem to indicate that the authorization header is not being received (or, less likely, is being altered in some way before receipt).

I have verified that the authorization header itself works correctly when sent via https://reqbin.com/curl.

In looking for answers, I came across several cases similar to mine. Some suggested additions to my .htaccess file—I tried these with no effect. Other cases indicated an issue with my $_SERVER['HTTP_AUTHORIZATION'] setting and/or the settings viewable through apache_request_headers().

Both of these values are empty. I've verified the $_SERVER['HTTP_AUTHORIZATION'] in my phpinfo file is set to 'no value', and there is no entry at all for $_SERVER['REDIRECT_HTTP_AUTHORIZATION'].

To be honest, I don't really know what any of this means. I'm barely competent in modifying Googled PHP scripts for my own use. But I have verified through reqbin that the information I'm sending is correct, and that the same information sent from my own server gets a response indicating a bad/mission authorization header.

Is it possible that the 'no value' setting for my $_SERVER['HTTP_AUTHORIZATION'], and the matching lack of an authorization key in apache_request_headers() is the issue? Would that prevent me from sending authorization headers, or alter them in some way before sending? If it matters, here's the code I'm using to send the headers:

$header_auth = 'Bearer ' . $access_token;
$body = array(
  'query'=>'some request'
);
$body_json = wp_json_encode($body);
$info_response = wp_remote_post('https://somewebsite.com/api/graphql/v1/',array(
  'headers' => array(
    'Authorization' => $header_auth,
    'Content-Type' => 'application/json'
  ),
  'body' => $body_json
));

已采纳解答

原帖链接 · Eye Teeth · CC BY-SA 4.0

With thanks to @Stephen Ostermiller and @davidgo, .htaccess and $_SERVER variables are not for outgoing queries. If there is a question of what exactly is being sent in your outgoing queries, change your endpoint to https://httpbin.org/anything, which will return all of the headers and contents of your query.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。