2024-05-15 10:21:45 发布
网友
希望有人能在这方面帮助我。 我在.SH中编写了一个API来获取消息的详细信息
curl --silent -k --header "PRIVATE-TOKEN:$GITLAB_AUTH_TOKEN"** *and some code*
在这里,当硬编码PRIVATE-TOKEN时,脚本工作正常,但是当我使用这个变量时,它就不工作了
PRIVATE-TOKEN
有人能提出为什么会发生这种情况以及可能的解决办法吗
我首先检查变量是否设置正确:
echo "GITLAB_AUTH_TOKEN='${GITLAB_AUTH_TOKEN}'"
请注意${GITLAB_AUTH_TOKEN}周围的简单引号:它有助于可视化标记后面是否有多余的空间,这可能会有问题
${GITLAB_AUTH_TOKEN}
为了安全起见,我将使用${}语法:
${}
curl silent -k header "PRIVATE-TOKEN: ${GITLAB_AUTH_TOKEN}"
我还将对 verbose而不是 silent执行相同的命令,以便查看curl正在做什么(用于测试)
verbose
silent
curl
注意PRIVATE-TOKEN:和标记之间的空格。 见GitLab API / Personal/project access tokens
PRIVATE-TOKEN:
Example of using the personal or project access token in a parameter:curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>" Example of using the personal or project access token in a header:curl header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects" You can also use personal or project access tokens with OAuth-compliant headers:curl header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"
Example of using the personal or project access token in a parameter:
curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>"
Example of using the personal or project access token in a header:
curl header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects"
You can also use personal or project access tokens with OAuth-compliant headers:
curl header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"
我首先检查变量是否设置正确:
请注意
${GITLAB_AUTH_TOKEN}
周围的简单引号:它有助于可视化标记后面是否有多余的空间,这可能会有问题为了安全起见,我将使用
${}
语法:我还将对
verbose
而不是silent
执行相同的命令,以便查看curl
正在做什么(用于测试)注意
PRIVATE-TOKEN:
和标记之间的空格。见GitLab API / Personal/project access tokens
相关问题 更多 >
编程相关推荐