CURL转义单引号 [英] CURL escape single quote

查看:1205
本文介绍了CURL转义单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何进行这项工作?

How can I make this work?

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的文件运行它,但是它也不能从命令行运行.我尝试使用\'\\'\u0027(Unicode ')

The ' in Mary's is causing this to fail. I am running it from a file like cat curl-cmd.txt | sh but it won't work from the command line either. I've tried using \' and \\' and \u0027 (the unicode ')

我被困住了

推荐答案

我遇到了同样的问题.最简单的解决方案是,除了用单引号引起来的撇号外,还要使用反斜杠来使撇号转义. '\''

I had the same problem. The simplest solution is to escape the apostrophe with a backslash in addition to wrapping it in a set of single quotes. '\''

对于您的用例,将Mary's更改为Mary'\''s,它应该可以工作.

For your use case, change Mary's to Mary'\''s and it should work.

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字符串中所有嵌套的双引号出现.

An alternate approach is to wrap the POST data (-d) in double quotes while escaping all nested occurrences of double quotes in the JSON string with a backslash.

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转义单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆