【发布时间】:2012-12-30 14:36:38
【问题描述】:
以下是浏览器(例如 Firefox)中的有效查询:
http://www.freesound.org/api/sounds/search/?q=barking&api_key=074c0b328aea46adb3ee76f6918f8fae
生成 JSON 文档:
{
"num_results": 610,
"sounds": [
{
"analysis_stats": "http://www.freesound.org/api/sounds/115536/analysis/",
"analysis_frames": "http://www.freesound.org/data/analysis/115/115536_1956076_frames.json",
"preview-hq-mp3": "http://www.freesound.org/data/previews/115/115536_1956076-hq.mp3",
"original_filename": "Two Barks.wav",
"tags": [
"animal",
"bark",
"barking",
"dog",
"effects",
...
我正在尝试使用Dispatch 0.9.4 执行此查询。这是build.sbt:
scalaVersion := "2.10.0"
libraryDependencies += "net.databinder.dispatch" %% "dispatch-core" % "0.9.4"
来自sbt console,我执行以下操作:
import dispatch._
val q = url("http://www.freesound.org/api/sounds/search")
.addQueryParameter("q", "barking")
.addQueryParameter("api_key", "074c0b328aea46adb3ee76f6918f8fae")
val res = Http(q OK as.String)
但承诺总是以以下错误完成:
res0: dispatch.Promise[String] = Promise(!Unexpected response status: 301!)
那我做错了什么? Here is the API documentation 以防万一。
【问题讨论】:
-
q OK as.String打印什么? (另外,你知道 301 是“永久移动”的代码,对吧?) -
@rex
(http://www.freesound.org/api/sounds/search GET,dispatch.OkFunctionHandler@7fc4fe21)。我对 HTTP 不太了解,但是如果我将 url 放在浏览器中,它就可以完美地工作。
标签: scala http scala-dispatch