gpt4 book ai didi

yii2 Rest api basic auth 抛出 401 未经授权

转载 作者:行者123 更新时间:2023-12-02 20:47:26 25 4
gpt4 key购买 nike

我正在使用 yii2 REST Api basicauth 开发一个 api。我已经在本地xampp服务器上开发成功了。我已将代码部署到运行 centos 的 vps 上。但我收到以下未经授权的回复:

{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}

我已经正确设置了标题。

响应 header :

Connection →Keep-Alive
Content-Type →application/json; charset=UTF-8
Date →Fri, 05 May 2017 08:40:49 GMT
Keep-Alive →timeout=5, max=100
Server →Apache
Transfer-Encoding →chunked
Www-Authenticate →Basic realm="api"
X-Powered-By →PHP/5.6.30


my headers:
Authorization : Basic BVrVm3Ay0jg2XBr3TeITaClg
Content-Type : application/x-www-form-urlencoded

当我转储 header 时,我看不到授权 header :

object(yii\web\HeaderCollection)#81 (1) {
["_headers":"yii\web\HeaderCollection":private]=>
array(10) {
["content-type"]=>
array(1) {
[0]=>
string(33) "application/x-www-form-urlencoded"
}
["accept"]=>
array(1) {
[0]=>
string(3) "*/*"
}
["accept-encoding"]=>
array(1) {
[0]=>
string(19) "gzip, deflate, sdch"
}
["accept-language"]=>
array(1) {
[0]=>
string(14) "en-US,en;q=0.8"
}
["cache-control"]=>
array(1) {
[0]=>
string(8) "no-cache"
}
["connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["cookie"]=>
array(1) {
[0]=>
string(172) "_csrf=ed46321a4d6f68c815e71201a9d47fa4594bc7dc66346fe10111269e612fa24ea%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22afHivmMVT9TeQ24W-jwdIBu5sx4nA_hY%22%3B%7D"
}
["host"]=>
array(1) {
[0]=>
string(14) "104.238.73.161"
}
["postman-token"]=>
array(1) {
[0]=>
string(36) "b2123a9e-1585-5a44-4af1-dab9f12951c6"
}
["user-agent"]=>
array(1) {
[0]=>
string(113) "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
}
}
}

知道为什么远程服务器会发生这种情况吗?请帮忙。

最佳答案

大家好,对于遇到此问题的任何人,我都找到了解决方案。

我在 .htaccess 文件中添加了以下行,问题已解决。

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

我从下面的线程中找到了解决方案: https://github.com/yiisoft/yii2/issues/6631

关于yii2 Rest api basic auth 抛出 401 未经授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43800420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com