Spring MVC : The request sent by the client was syntactically incorrect

后端 未结 6 525
一个人的身影
一个人的身影 2021-01-02 20:49

When sending JSON requests to the server, I\'m often greeted by this message:

The request sent by the client was syntactically incorrect ().

6条回答
  •  旧时难觅i
    2021-01-02 21:46

    Old case, my be irrelevant by now, but for others with similar trouble I'll add this entry.

    Check that you have double quotes, not single quotes. Also try escaping them.

    I used the app curl for my test json requests.

    My JSON was like this

    { 'name' : 'somedata', 'town':'some town' } 
    

    and it just blew up in my eyes.

    "The request sent by the client was syntactically incorrect" was the general error. So I changed it from single quotes to double quotes, no go. I then tried having a backslash infront of the single quotes, still no go. Then changed it to backslash infront of the double quotes and presto!

    curl -i -H "Accept: application/json" -H "Content-Type: application/json" \ 
    http://localhost:8077/dra/dump.json \ 
    -X PUT -d "{\"name\" : \"My Name\", \"town\":\"My Town\"}" 
    

提交回复
热议问题