简体   繁体   中英

Json media types for requests in Scala Spray

I have a simple json app. It works fine if I make a request like

curl -X POST --data "userId=1" http://localhost:8080/register

But request fails when I try to make a json request, eg

curl -v -H "Content-type: application/json" -X POST -d '{"userId"=1}' http://localhost:8080/register

> Content-type: application/json
>
< HTTP/1.1 415 Unsupported Media Type
< Server: spray-can/1.3.3
< Date: Mon, 07 Sep 2015 14:37:29 GMT
< Content-Type: text/plain; charset=UTF-8
<

Expected 'application/x-www-form-urlencoded' or Expected 'multipart/form-data'

How to ask Spray to process json request?

Your curl command looks correct except for this part: '{"userId"=1}' . This is not a valid JSON document. It should be this instead '{"userId" : 1}' . I think that's why you getting this error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM