我正在尝试做这样的事情:
#!/bin/bash
for (( ; ; ))
do
IP="$(
curl -s http://whatismijnip.nl |cut -d " " -f 5
)"
curl -X PUT "https://api.cloudflare.com/client/v4/zones/fc4a89d0f0a71df7969d3f6d32ef5c61/dns_records/dfa4ae7f9d7b99745a6a09e40c12b7f5"
-H "Content-Type:application/json"
-H "X-Auth-Key: U Dont Have To Know This"
-H "X-Auth-Email:[email protected]"
-d "{"id":"dfa4ae7f9d7b99745a6a09e40c12b7f5","type":"A","name":"ts.javelcraft.com","content":"'"$IP"'","proxiable":true,"proxied":false,"ttl":1,"locked":false,"zone_id":"fc4a89d0f0a71df7969d3f6d32ef5c61","zone_name":"javelcraft.com","created_on":"0000-00-00T00:00:00.000000Z","modified_on":"0000-00-00T00:00:00.000000Z","data":{}}"
done
pause
但它返回此错误:
{"success":false,"errors":[{"code":6007,"message":"Malformed JSON in request body"}],"messages":[],"result":null}
也就是说-d后面的“”里的json文本写错了。
答案1
尝试这个 :
#!/bin/bash
for (( ; ; ))
do
IP="$(
curl -s http://whatismijnip.nl |cut -d " " -f 5
)"
#
JSONSTRING='{"id":"dfa4ae7f9d7b99745a6a09e40c12b7f5","type":"A","name":"ts.javelcraft.com","content":"'$IP'","proxiable":true,"proxied":false,"ttl":1,"locked":false,"zone_id":"fc4a89d0f0a71df7969d3f6d32ef5c61","zone_name":"javelcraft.com","created_on":"0000-00-00T00:00:00.000000Z","modified_on":"0000-00-00T00:00:00.000000Z","data":{}}'
#
curl -X PUT "https://api.cloudflare.com/client/v4/zones/fc4a89d0f0a71df7969d3f6d32ef5c61/dns_records/dfa4ae7f9d7b99745a6a09e40c12b7f5"
-H "Content-Type:application/json"
-H "X-Auth-Key: U Dont Have To Know This"
-H "X-Auth-Email:[email protected]"
-d $JSONSTRING
# PRINT PRETTY JSON FORMAT
echo $JSONSTRING | python -mjson.tool
done
pause