windows 窗口:curl:(3)URL使用错误/非法格式或缺少URL [重复]

ffscu2ro  于 2023-05-08  发布在  Windows
关注(0)|答案(2)|浏览(595)

此问题已在此处有答案

How to send double quote in -d parameter for curl.exe?(6个回答)
昨天关门了。
我在GitLab中有一个名为my_package_registry_2.0.4.0的现有包注册表。现在,我使用curl命令尝试创建一个新的Release,同时将该包注册表作为资产添加。我的标签1.0.0.0也存在,并且已经在我的存储库中创建。
下面是curl命令(没有里程碑日期,我对它不感兴趣):

curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: myTokenHere" --data '{ "name": "2.0.0.0", "tag_name": "1.0.0.0", "description": "Release manually created from API", "assets": { "links": [{ "name": "Release_1.2.0.0", "url": "https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip", "link_type":"package" }] } }' --request POST "https://my.gitlab.space/api/v4/projects/197/releases"

当我执行它时,它正在失败。下面是错误:

curl: (6) Could not resolve host: application
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched brace in URL position 1:
{
 ^

我做错了什么?

尝试#2:如果我使用双引号而不是单引号,我的意思是,替换:

'Content-Type : application/json'

通过

"Content-Type : application/json"

然后我得到下面的错误:

curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched brace in URL position 1:
{
 ^
vddsk6oq

vddsk6oq1#

最后我解决了这个问题,从cmd.exe执行它需要把所有的东西放在双引号内,并在其他双引号内转义双引号,就像这样:

curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: myTokenHere" --data "{ \"name\": \"2.0.0.0\", \"tag_name\": \"1.0.0.0\", \"description\": \"Release manually created from API\", \"assets\": { \"links\": [{ \"name\": \"Release_1.2.0.0\", \"url\": \"https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip\", \"link_type\":\"package\" }] } }" --request POST "https://my.gitlab.space/api/v4/projects/197/releases"
xam8gpfp

xam8gpfp2#

您似乎正在使用cmd.exe。引用样式与Unix* 工具不同。为此,您需要在PowerShell中运行相同的命令。
您可以缩短命令并像这样拆分它:

curl.exe --header 'Content-Type: application/json' \
     --header "PRIVATE-TOKEN: myTokenHere" \
     --data '{ "name": "2.0.0.0", "tag_name": "1.0.0.0", "description": "Release manually created from API", "assets": { "links": [{ "name": "Release_1.2.0.0", "url": "https://my.gitlab.space/api/v4/projects/197/packages/generic/my_package_registry_2.0.4.0/1.0.0.0/myZipFile.zip", "link_type":"package" }] } }' \
    "https://my.gitlab.space/api/v4/projects/197/releases"

--data意味着已经有一个POST请求。

相关问题