REST POST controller saying: Could not read JSON: No content to map due to end-of-input

前端 未结 2 1356
孤独总比滥情好
孤独总比滥情好 2020-12-09 04:24

I\'m doing an integration test against a REST controller POST handler. Well, I\'m trying to.

It gives me the HttpMessageNotReadableException exception: Could not rea

2条回答
  •  被撕碎了的回忆
    2020-12-09 05:03

    In my opinion the problem is with content format. Your endpoint expect that data will be sent as application/json but in test you send it as application/x-www-form-urlencoded (it doesn't matter that you set proper content type header in request). Try to send admin object in json format (as a body of a request):

    {
     "firstname" : "Stephane",
     "lastname" : "Eybert",
     "login" : "stephane",
     "password" : "toto"
    }
    

    BTW the /admin/crud does not fallow REST resource addressing rules, you should change it to /admin. The crud (CREATE, READ, UPDATE, DELETE) will map to HTTP methods (POST, GET, PUT, DELETE)

提交回复
热议问题