CURL escape single quote

后端 未结 2 1795
余生分开走
余生分开走 2020-12-13 03:53

How can I make this work?

curl -XPOST \'http://localhost:9290/location/place\' -d \'{\"geoloc\": {\"lat\": \"38.1899\", \"lon\": \"-76.5087\"}, \"longitude\"         


        
2条回答
  •  被撕碎了的回忆
    2020-12-13 04:33

    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. '\''

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

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

提交回复
热议问题