gpt4 book ai didi

javascript - 第三方REST API基础认证

转载 作者:行者123 更新时间:2023-12-03 06:21:57 24 4
gpt4 key购买 nike

我使用团队合作项目管理工具。我正在尝试使用团队合作提供的 REST api 创建一个 Web 应用程序。但这需要一些身份验证。我已阅读团队合作文档,这就是他们所说的

身份验证

身份验证使用 HTTP 身份验证进行管理(目前仅支持“基本”)。每个请求都必须包含授权 HTTP header 。使用您的 API token 作为用户名,使用“X”(或其他虚假文本)作为密码(仅 API token 用于验证 API 请求)。

Curl 示例:

curl -H 'Accept: application/json' -H 'Content-Type: application/json' \
-u APIKEY0123456789:xxx -d '{"request": {"name": "some value"}}' https://yours.teamwork.com

我查看了一些在线教程并编写了以下代码

public function portalLogin()
{
//cURL
// phpinfo(); //curl is enabled
$channel = curl_init();
//options
curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/projects.json?status=LATE");
curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authoritation:BASIC".base64_encode("secretApiCode:xxx")));
echo curl_exec($channel); //return 1
curl_close($channel);
}

这返回1。我不知道这意味着什么。我不知道我做的是否正确。这是受身份验证保护的团队合作 API 所在的位置。

http://projects.abounde.com/projects.json

我的最终目标是为不同的用户提供不同的用户名和密码,他们将输入不同的用户名和密码,系统将从数据库中找到 key 并从特定用户加载项目列表。

最佳答案

public function portalLogin()
{
//cURL
// phpinfo();
$username = "night720elvis";
$password = "xxx";
$channel = curl_init();
//options
curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/projects.json?status=LATE");
//curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authoritation:BASIC".base64_encode("night720elvis:xxx")));

curl_setopt($channel, CURLOPT_HTTPHEADER,
array(
"Authorization: Basic " . base64_encode($username . ":" . $password)
));
echo curl_exec($channel);
curl_close($channel);
}

这验证了

关于javascript - 第三方REST API基础认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38827896/

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