我该如何工作?
curl -XPOST 'http://localhost:9290/location/place' -d '{"geoloc": {"lat": "38.1899", "lon": "-76.5087"}, "longitude": "-76.5087", "admin_name1": "Maryland", "admin_name2": "St. Mary's", "admin_name3": "", "postal_code": "20692", "admin_code3": "", "country_code": "US", "admin_code1": "MD", "latitude": "38.1899", "admin_code2": "037", "accuracy": null, "place_name": "Valley Lee"}'
将'在Mary's引起此故障。我从类似的文件运行它,cat curl-cmd.txt | sh但也无法从命令行运行。我试过使用\'and \\'和\u0027(unicode ')
'
Mary's
cat curl-cmd.txt | sh
\'
\\'
\u0027
我被卡住了
我有同样的问题。最简单的解决方案是,除了用单引号引起来的撇号外,还要使用反斜杠来将其引起来。'\''
'\''
对于您的用例,更改Mary's为Mary'\''s,它应该可以工作。
Mary'\''s
curl -XPOST 'http://localhost:9290/location/place' -d '{"geoloc": {"lat": "38.1899", "lon": "-76.5087"}, "longitude": "-76.5087", "admin_name1": "Maryland", "admin_name2": "St. Mary'\''s", "admin_name3": "", "postal_code": "20692", "admin_code3": "", "country_code": "US", "admin_code1": "MD", "latitude": "38.1899", "admin_code2": "037", "accuracy": null, "place_name": "Valley Lee"}'
另一种方法是将POST数据(-d)用双引号引起来,同时用反斜杠转义JSON字符串中所有嵌套的双引号。
-d
curl -XPOST 'http://localhost:9290/location/place' -d "{\"geoloc\": {\"lat\": \"38.1899\", \"lon\": \"-76.5087\"}, \"longitude\": \"-76.5087\", \"admin_name1\": \"Maryland\", \"admin_name2\": \"St. Mary's\", \"admin_name3\": \"\", \"postal_code\": \"20692\", \"admin_code3\": \"\", \"country_code\": \"US\", \"admin_code1\": \"MD\", \"latitude\": \"38.1899\", \"admin_code2\": \"037\", \"accuracy\": null, \"place_name\": \"Valley Lee\"}"