php - pass a variable inside bear token
问题描述
I can pass the bearer token using the following code in my php script:
$headers = array(
'Authorization' => 'Bearer blablablabla',
'Content-type' => 'application/json'
);
The above succeeds connecting. The problem is I have to pass the above token (blablabla) which comes from variable called $token.
I tried to pass like the below
$headers = array(
'Authorization' => 'Bearer $token',
'Content-type' => 'application/json'
);
But the above did not work and got denied. Therefore $token is not passed inbetween single quotes with space.
How can I achieve this?
解决方案
You should use double quotation marks to pass a variable into a string. For example:
$headers = array(
'Authorization' => "Bearer $token",
'Content-type' => 'application/json'
);
Or you can use concatenation:
$headers = array(
'Authorization' => 'Bearer ' . $token,
'Content-type' => 'application/json'
);
推荐阅读
- android - Android Robolectric 异常
- html - 在html上添加指向本地文件的链接
- scala - 从可能不存在的插件调用任务
- django - 如何在 django thag 中创建一个搜索栏,根据所采取的选择过滤查询集?
- reactjs - useState 不支持第二次回调,有什么简单的解决方法?
- android - Google Play 发布前报告安全漏洞,表明所有域都允许明文流量
- python-3.x - 如何管理分布式系统中的速率限制?
- mongodb - 如何查找对象数组,并且每个对象都有每个对象的不同 ObjectId
- sql - 我们可以从sql中的列中选择第一行数据吗?
- javascript - 将两个数组中的数据添加到 CSV 输出中