guigui guigui - 1 year ago 122
Scala Question

Play Scala - Have a POST method without JSON

I wanted to know if there were any ways to have a POST call on my Play framework REST API without any JSON in the call.

I'm making the API with the logic that if you create anything in the database, then you need to make a POST call, but yet I have this issue that occurs right when it hits the API :

Bad Request

For request 'POST /promotions/add/user?userId=41375&promoId=24265'
[Invalid Json: No content to map due to end-of-input at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@a5de52b; line: 1, column: 0]]

Is there a way or I have to change the call in GET or make otherwise with userId and promoId in a JSON, which I would like to avoid.

Thanks !

hgx hgx
Answer Source

Please check if you have set any content-type in the request. Also check how the requests are handled within the action method like using<XXX> etc.

If your POST request is not using the json as the data payload, you may use a form to be bound from the request. In that case, make sure that you have set the Content-Type: application/x-www-form-urlencoded in the request. Sometimes, it doesn't matter you set proper content type header in request. It all depends on how POST request is handled by the controller action methods/API endpoints.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download