2014-10-16 163 views
1

我在Scala中用Rapture构建了一个API,并且无法解决隐式不在范围内的问题。以下是我收到的错误的输出。用Rapture获取请求Http

[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我找不到一个。我无法找到一种方法将查询字符串传递到rapture-uri中,因为它期望函数调用看起来像这样uri"url_dot_domain_with_query_strings".slurp[Char]

任何想法?

+0

我想你是在Sbtb提到* Jon Pretty *? – 2015-03-25 17:52:55

回答

2

在这种情况下编译错误并不完全正确。您需要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] 
}