得到以下是在瀏覽器(如Firefox)的一個有效的查詢:執行一個簡單的HTTP和訊
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確定as.String'打印? (另外,你知道301是「永久移動」的代碼,對吧?) –
@rex'(http://www.freesound.org/api/sounds/search GET,dispatch.OkFunctionHandler @ 7fc4fe21)'。我對HTTP沒有很好的瞭解,但是如果我把URL放在瀏覽器中,它就可以完美工作。 –