Flask RESTful POST JSON fails

后端 未结 3 1587
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 04:33

I have a problem posting JSON via curl from cmd (Windows7) to Flask RESTful. This is what I post:

curl.exe -i -H \"Content-Type: application/json\" \\
 -H \"Acce         


        
相关标签:
3条回答
  • 2021-02-10 04:44

    I just want to point out that you need to escape regardless of OS - and regardless if you have double quotes around the request data - I saw this post and didn't think it was the answer to my issue because I had double quotes around the request data and single quotes inside:

    This won't work:

    -d "{'Hello': 'Karl'}"
    

    This will:

    -d "{\"Hello\":\"Karl\"}"
    

    Again, you need to escape the quotes regardless of OS (I'm on Mac) and regardless of whether you have single or double quotes

    And thanks Sabuj Hassan for your answer!

    0 讨论(0)
  • 2021-02-10 04:49

    -d '{"Hello":"Karl"}' doesn't work from windows as its surrounded by single quotes. Use double quotes around and it will work for you.

    -d "{\"Hello\":\"Karl\"}"
    
    0 讨论(0)
  • 2021-02-10 05:02

    To add-on to the previous two answers, you do not need to escape the quotes across all OS's, following this syntax will work just fine on Mac/Linux:

    -d '{"Hello":"Karl"}'
    
    0 讨论(0)
提交回复
热议问题