2

我需要使用 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 的常见替代品也适用于我。

4

1 回答 1

1

终于让它工作了:

base64 --wrap 0 GeoIP.dat > GeoIP.dat.base64
curl -vvvv -X PUT  \
     --header "PRIVATE-TOKEN: ${TOKEN}" \
     --data-urlencode "author_email=autoupdate-geoip@company.com" \
     --data-urlencode "author_name=Autoupdater GeoIP" \
     --data-urlencode "branch=${BRANCH_NAME}" \
     --data-urlencode "commit_message=Autoupdate GeoIP Database" \
     --data-urlencode "encoding=base64" \
     --data-urlencode "file_path=some/path/geoip/GeoIP.dat" \
     --data-urlencode content@GeoIP.dat.base64 \
     "${GEOIP_URL}" | python -m json.tool
于 2018-01-05T16:58:52.963 回答