Why do I get a malformed JSON in request body in this cURL call?

后端 未结 2 1283
滥情空心
滥情空心 2021-01-11 16:43

I have been trying to call the CloudFlare API v4, using an example provided in their own documentation.

This is the code of the example

curl -X PUT \         


        
相关标签:
2条回答
  • 2021-01-11 17:22

    cmd.exe doesn't support single quotes, to run those commands straight from the docs you can use Bash.

    Bash can be enabled in Windows 10 : https://www.laptopmag.com/uk/articles/use-bash-shell-windows-10

    or Git Bash comes with Git for windows: https://gitforwindows.org/

    0 讨论(0)
  • 2021-01-11 17:38

    Frank.Lowell, thank you for question!

    I found the answer in the blog post: "Expecting to find valid JSON in request body..." curl for Windows.

    For example, for Purge everything --data value will be:

    # On Linux
    --data '{"purge_everything":true}'
    
    # On Windows
    --data "{\"purge_everything\":true}"
    

    For Windows:

    1. Replace the single quotes with double quotes: ' --> "
    2. Escape the double quotes with a backslash: " --> \"
    0 讨论(0)
提交回复
热议问题