英文:
Passing key and pem file data in curl command not working
问题
我正在尝试使用curl
命令调用API,但不幸的是,我无法保留文件。我正在尝试在命令中传递.key
和.pem
文件的数据,但我无法正确传递。以下是我的.sh
文件中的命令:
response=$(curl --key "$5" --cert "$6" -k -X "$2" -d "$payload" "$4")
我以以下方式调用脚本:
key="${key}"
pem="${pem}"
bash ./Integration1.sh Provision POST "$payload" https://some-api.com/pr "$key" "$pem"
它给出以下错误:
curl: (58) could not load PEM client certificate from -----BEGIN CERTIFICATE-----
如果我直接传递文件,此命令可以正常工作,所以是否有办法通过字符串变量在curl命令中传递数据?
英文:
I am trying to invoke the API using the curl
command but unfortunately, I won't be able to keep the files. I am trying to pass the .key
and .pem
file's data in the command but I am not able to pass that correctly. Below is my command in my .sh
file:
response=$(curl --key "$5" --cert "$6" -k -X "$2" -d "$payload" "$4")
I am calling the script below way:
key="${key}"
pem="${pem}"
bash ./Integration1.sh Provision POST "$payload" https://some-api.com/pr "$key" "$pem"
It gives the below error:
curl: (58) could not load PEM client certificate from -----BEGIN CERTIFICATE-----
This command works fine if I pass the file directly so, is there any way to pass the data via string variables in the curl command?
答案1
得分: 2
如果您只有将密钥数据存储在一个变量中,由于某种原因无法将其自己写入文件,另一种解决方案是使用进程替代。
<(printf '%s' "$key") \
<(printf '%s' "$pem")
这需要使用bash,并在底层仍然使用文件,但它不需要您自己管理文件或知道它们的位置。
英文:
If you only have your key data in a variable and can't write it to a file yourself for some reason, an alternative solution is to use process substitution.
bash ./Integration1.sh Provision POST "$payload" https://some-api.com/pr \
<(printf '%s' "$key") \
<(printf '%s' "$pem")
This requires bash and still uses files under the hood, but it doesn't require you to manage the files yourself or know where they're located.
答案2
得分: 1
--key
和 --cert
需要输入包含证书数据的文件的名称,而不是证书数据本身。
... "$(cat my_client.key)" "$(cat my_client.pem)"
应该改为
... my_client.key my_client.pem
英文:
--key
and --cert
take the name of a file containing certificate data, not the certificate data itself.
... "$(cat my_client.key)" "$(cat my_client.pem)"
Should just be
... my_client.key my_client.pem
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论