我使用http4s客户端库
编写了以下代码import org.http4s.UrlForm
import org.http4s.Uri
import org.http4s.client.blaze.SimpleHttp1Client
import org.http4s.dsl._
import org.http4s.client._
val requestUrl = s"$url/foo/bar"
val client = SimpleHttp1Client()
val uri = Uri.fromString(requestUrl).valueOr(throw _)
val req = POST(uri, UrlForm("name" -> "foo"))
val result = client.expect[String](req).run
println(result)
但这会出现异常
[error] Exception in thread "main" java.lang.NoSuchMethodError: scalaz.syntax.std.package$option$.ToOptionIdOps(Ljava/lang/Object;)Lscalaz/syntax/std/OptionIdOps;
[error] at org.http4s.parser.Rfc3986Parser$class.HierPart(Rfc3986Parser.scala:33)
[error] at org.http4s.parser.RequestUriParser.HierPart(RequestUriParser.scala:9)
[error] at org.http4s.parser.Rfc3986Parser$class.AbsoluteUri(Rfc3986Parser.scala:21)
[error] at org.http4s.parser.RequestUriParser.AbsoluteUri(RequestUriParser.scala:9)
[error] at org.http4s.parser.Rfc3986Parser$class.Uri(Rfc3986Parser.scala:18)
我的sbt依赖是
libraryDependencies ++= Seq(
"org.http4s" % "http4s-core_2.11" % "0.15.3"
"org.http4s" % "http4s-blaze-client_2.11" % "0.15.3"
"org.http4s" %% "http4s-argonaut" % "0.15.3"
"org.http4s" % "http4s-dsl_2.11" % "0.15.3"
"org.http4s" %% "http4s-client" % "0.15.3"
)
答案 0 :(得分:2)
我为你清理了一下:
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-core" % "0.15.3",
"org.http4s" %% "http4s-blaze-client" % "0.15.3",
"org.http4s" %% "http4s-argonaut" % "0.15.3",
"org.http4s" %% "http4s-dsl" % "0.15.3",
"org.http4s" %% "http4s-client" % "0.15.3"
)
scalaVersion := "2.11.8"
我无法用它重现它。我安装了https://github.com/jrudolph/sbt-dependency-graph并查看是否有一些依赖于scalaz 7.1 / 7.2的库 - here's the matrix
对于URI处理,有a tiny bit of doc。