我需要使用 Gitlab API 发送一个带有 curl (v.7.35.0)的PUTkey=value
请求,其中包含一些参数。密钥content
需要是二进制文件内容。所以我需要将它作为base64发送,但我之前已经失败了。然而,1.2MB 的大文件内容是我必须使用标准输入的原因,因为 curl 与其他语法抱怨太大的 URI / 参数列表。
从https://unix.stackexchange.com/questions/174350/curl-argument-list-too-long获取一些输入 。但是在 curl 中的参数组合仍然有点迷失。
DATA="{
\"author_email\": \"autoupdate-geoip@company.com\",
\"author_name\": \"Autoupdater GeoIp\",
\"branch\": \"${BRANCH_NAME}\",
\"content\": \"this-should-be-file-content-of-GeoIP.dat\",
\"commit_message\": \"Update GeoIP database\"
\"encoding\": \"base64\"
}"
curl -X PUT -G "${GEOIP_URL}" \
--header "PRIVATE-TOKEN: ${TOKEN}" \
--header "Content-Type: application/json" \
--data-urlencode @- <<EOF
"${DATA}"
EOF
curl 的常见替代品也适用于我。