Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

linux - How to send double quotes inside JSON curl request

I want to send this string inside a CURL request from shell script :

"google-site-verification=O_Kd7lqvCvpBz7fzEeUKGVKBmsAsfJgaJuh3PZRnrsk"

To do that I'm using this script :

OVH_HTTP_METHOD="POST"
OVH_HTTP_QUERY="$OVH_API_URL/$OVH_API_END_POINT_DOMAIN_ZONE_DNS/domain.com/$OVH_API_END_POINT_DOMAIN_ZONE_DNS_RECORD"
OVH_FIELD_TYPE="TXT"
OVH_SUB_DOMAIN=""
OVH_TARGET=""google-site-verification=O_Kd7lqvCvpBz7fzEeUKGVKBmsAsfJgaJuh3PZRnrsk""
OVH_HTTP_BODY="{"fieldType":"$OVH_FIELD_TYPE","subDomain":"$OVH_SUB_DOMAIN","target":"$OVH_TARGET"}"

curl -X $OVH_HTTP_METHOD 
    $OVH_HTTP_QUERY 
    -H "Content-Type: application/json" 
    -H "X-Ovh-Application: $OVH_API_APPLICATION_KEY" 
    -H "X-Ovh-Timestamp: $OVH_TIME" 
    -H "X-Ovh-Signature: $OVH_SIG" 
    -H "X-Ovh-Consumer: $OVH_API_CONSUMER_KEY" 
    --data "$OVH_HTTP_BODY"

But I get systematically this error message :

{"message":"Invalid JSON received","httpCode":"400 Bad Request","errorCode":"INVALID_JSON"}

UPDATE with curl -v :

enter image description here

Do you have any idea to solve that?

Thanks L.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

solution found below : variable has to be escaped like this :

OVH_TARGET="\"google-site-verification=O_Kd7lqvCvpBz7fzEeUKGVKBmsAsfJgaJuh3PZRnrsk\""

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...