CURL转义单引号

我该如何工作?

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'sMary'\''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字符串中所有嵌套的双引号。

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\"}"

以上是 CURL转义单引号 的全部内容, 来源链接: utcz.com/qa/435953.html

回到顶部