gpt4 book ai didi

api - 想知道为什么尝试使用 cURL 将 Letsencrypt .pem 证书上传到 Cloudflare API 会抛出 "Malformed JSON in request body"错误?

转载 作者:太空宇宙 更新时间:2023-11-03 14:29:42 26 4
gpt4 key购买 nike

我有一个脚本试图替换我网站在 Cloudflare 上的 SSL 证书。Certbot 每三个月从 Letsencrypt 自动更新本地服务器上的证书。现在,需要使用其 API 将 certbot 更新的 SSL .pem 证书上传到 Cloudflare。

PRIVATE_KEY="/etc/letsencrypt/live/autoxxx.com.au/privkey.pem"

CERTIFICATE="/etc/letsencrypt/live/aautoxxx.com.au/cert.pem"

# read from files
PRIVATE_KEY=`cat $PRIVATE_KEY`
CERTIFICATE=`cat $CERTIFICATE`

DATA='{"private_key":"'$PRIVATE_KEY'","certificate":"'$CERTIFICATE'","bundle_method":"ubiquitous"}'

curl -i \
-X PATCH "https://api.cloudflare.com/client/v4/zones/rCWR4i3A24NZEzI4dFLYLAhU7tUBtJUSYQkh/custom_certificates/iqXVG2FV8Cgj5FXGMexIoJovtFQx5UhecVya" \
-H "X-Auth-Email: webdev@autoxxx.com.au" \
-H "X-Auth-Key: pg5Q89JI33nsgdA9iZwPky3q" \
-H "Content-Type: application/json" \
-d "$DATA" --trace-ascii /dev/stdout

但是,运行这个脚本会抛出以下错误

{"success":false,"errors":[{"code":6007,"message":"Malformed JSON in request body"}],"messages":[],"result":null}

尝试引用建议作为对以下问题的回答,但仍然是同样的错误。

Why do I get a malformed JSON in request body in this cURL call?

最佳答案

我广泛地搜索了 Google。尝试了以下 https://docs.vmware.com/en/Unified-Access-Gateway/3.0/com.vmware.access-point-30-deploy-config.doc/GUID-870AF51F-AB37-4D6C-B9F5-4BFEB18F11E9.html将 .pem 放入一行。使用 awk 'NF {sub(/\r/, ""); printf "%s\n",$0;}' 来实现这一点,但现在它抛出了“无效证书”响应。

以下代码完美运行。上面的 awk 命令用新行\n 替换了回车符,但 Cloudflare 显然需要文字“\n”。

PRIVATE_KEY="/etc/letsencrypt/live/autoxxx.com.au/privkey.pem"

CERTIFICATE="/etc/letsencrypt/live/aautoxxx.com.au/cert.pem"

# read from file, put the .pem into single line and replace carriage returns with the literal "\n"
PRIVATE_KEY=`awk 'NF {sub(/\r/, ""); printf "%s\\\n",$0;}' $PRIVATE_KEY`
CERTIFICATE=`awk 'NF {sub(/\r/, ""); printf "%s\\\n",$0;}' $CERTIFICATE`

DATA='{"private_key":"'$PRIVATE_KEY'","certificate":"'$CERTIFICATE'","bundle_method":"ubiquitous"}'

curl -i \
-X PATCH "https://api.cloudflare.com/client/v4/zones/rCWR4i3A24NZEzI4dFLYLAhU7tUBtJUSYQkh/custom_certificates/iqXVG2FV8Cgj5FXGMexIoJovtFQx5UhecVya" \
-H "X-Auth-Email: webdev@autoxxx.com.au" \
-H "X-Auth-Key: pg5Q89JI33nsgdA9iZwPky3q" \
-H "Content-Type: application/json" \
-d "$DATA" --trace-ascii /dev/stdout

关于api - 想知道为什么尝试使用 cURL 将 Letsencrypt .pem 证书上传到 Cloudflare API 会抛出 "Malformed JSON in request body"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53760493/

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