1

我有一个简单的 json 应用程序。如果我提出这样的请求,它工作正常

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

但是当我尝试发出 json 请求时请求失败,例如

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'

如何让 Spray 处理 json 请求?

4

1 回答 1

1

除了这部分之外,您的 curl 命令看起来是正确的:'{"userId"=1}'. 这不是有效的 JSON 文档。应该是这个'{"userId" : 1}'。我认为这就是您收到此错误的原因。

于 2015-09-08T03:57:44.540 回答