小编Gau*_*tah的帖子

在 Dispatch 和 Scala 中使用 JSON POST 请求

我在使用 Dispatch 和 Scala 使用 JSON 对象发出 POST 请求时遇到问题。

POST 请求肯定可以正常工作,因为我使用 curl 对其进行了测试:

~/workspace $ curl -vd 'tracker={"project":"campaign","event":"home","number":"100"}'  http://exampleurl:8145/test
Run Code Online (Sandbox Code Playgroud)

我得到了预期的 HTTP 200 响应

但是当我尝试使用 Dispatch 库(http://dispatch.databinder.net/Dispatch.html)做同样的事情时:

scala> Http(url("http://exampleurl:8145/test") << "tracker={'project':'campaign','event':'home','number':'100'}" >|)
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

dispatch.StatusCode: Unexpected response code: 404
Paramerter missing: [tracker] not found
at dispatch.HttpExecutor$$anonfun$when$1.apply(executor.scala:53)
at dispatch.HttpExecutor$$anonfun$when$1.apply(executor.scala:50)
at dispatch.HttpExecutor$$anonfun$x$2.apply(executor.scala:41)
at dispatch.HttpExecutor$$anonfun$x$2.apply(executor.scala:36)
at dispatch.BlockingHttp$$anonfun$execute$1.apply(Http.scala:54)
at dispatch.Http.pack(Http.scala:25)
at dispatch.BlockingHttp$class.execute(Http.scala:53)
at dispatch.Http.execute(Http.scala:21)
at dispatch.HttpExecutor$class.x(executor.scala:36)
at dispatch.Http.x(Http.scala:21)
at dispatch.HttpExecutor$class.when(executor.scala:50)
at dispatch.Http.when(Http.scala:21)
at dispatch.HttpExecutor$class.apply(executor.scala:60)
at dispatch.Http.apply(Http.scala:21)
at .<init>(<console>:11)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>) …
Run Code Online (Sandbox Code Playgroud)

post json scala scala-dispatch

3
推荐指数
1
解决办法
5481
查看次数

标签 统计

json ×1

post ×1

scala ×1

scala-dispatch ×1