Posting JSON to REST API

后端 未结 9 834
-上瘾入骨i
-上瘾入骨i 2020-12-08 08:12

I\'m creating a REST API that will accept JSON requests.

I\'m testing it out using CURL:

curl -i -POST -H \'Accept: application/json\' -d \'{\"id\":1         


        
9条回答
  •  天命终不由人
    2020-12-08 08:57

    I had the same problem and I resolved it.

    1 add MappingJackson2HttpMessageConverter as described in that thread (see also section 4 http://www.baeldung.com/spring-httpmessageconverter-rest)

    2 use correct command (with escape symbols):

    curl -i -X POST -H "Content-Type:application/json" -d "{\"id\":\"id1\",\"password\":\"password1\"}" http://localhost:8080/user    
    

提交回复
热议问题