gpt4 book ai didi

scala - 使用 Rapture Http 获取请求

转载 作者:可可西里 更新时间:2023-11-01 17:09:10 25 4
gpt4 key购买 nike

我正在 Scala 中使用 Rapture 构建 API,但无法解决隐式不在范围内的问题。这是我收到的错误的输出。

[error] /Users/Petesta/Documents/scala-project/src/main/scala/scala-project/main.scala:35: an implicit TimeSystem is required; please import timeSystems.numeric or timeSystems.javaUtil
[error] Error occurred in an application involving default arguments.
[error] val response = h.get()
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 5 s, completed Oct 16, 2014 3:36:10 PM

这是失败的代码。

def getUser(userName: String) = {
val h = Http / "some_url" / "user" / userName /? Map('key -> "value")
val response = h.get()
}

我不确定该怎么做,因为我已经尝试分别导入这两个库,但错误仍然相同。

我还添加了 -Xlog-implicits 标志来查看是否有其他原因导致了错误,但没有输出额外的信息。

有没有关于使用 rapture-net 库处理 HTTP 请求的好资源?除了 Jon Pretty 在 Scala By The Bay 的幻灯片外,我找不到其他的。我想不出一种方法将带有查询字符串的 url 传递到 rapture-uri,因为它希望函数调用看起来像这样 uri"url_dot_domain_with_query_strings".slurp[Char]

有什么想法吗?

最佳答案

在这种情况下,编译错误并不完全正确。您需要 2 个导入中的 1 个并且需要指定超时值。

def getUser(userName: String) = {
import timeSystems.numeric
val h = Http / "some_url" / "user" / userName /? Map('key -> "value")
val response = h.get(timeout = 5000L)
}

我真的不知道有什么好的资源,但您的基本单行代码是正确的。该库最大的问题实际上是有关所需导入的文档。但这是我发现对我有用的:

def getGoogle() = {
import rapture.codec._
import rapture.io._
import rapture.uri._
import rapture.net._
import encodings.`UTF-8`
uri"http://google.com".slurp[Char]
}

关于scala - 使用 Rapture Http 获取请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26415147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com