2016-07-25 26 views
0

我有一個REST的API調用,看起來像下面的多參數:scalaj-HTTP上獲得

http://xxxxx:9000/api/parameter/value?ecosystem_name=streaming_pipeline&ecosystem_key_name=kafka_brokers 

當我使用它通過郵遞員或揚鞭,工作正常。當我運行scalaj-http:

val result = Http("http://xxxxxx:9000/parameter/value").params(Map(("ecosystem_name", "streaming_pipeline"), ("ecosystem_key_name", "kafka_brokers"))).asString 

我收到一條未找到的響應。這與其他呼叫工作時,我只使用一個參數:

val result = Http("http://xxxxxx:9000/api/schemas/name").param("schema_name", schemaName).asString 

爲什麼當我嘗試使用它似乎是失敗的多個參數?我嘗試使用.param(...).param(...)而不是.params也沒有運氣。

編輯基於:

scala> val result = Http("http://xxxxx:9000/parameter/value").params(Map("ecosystem_name" -> "streaming_pipeline", "ecosystem_key_name" -> "kafka_brokers")).asString 
result: scalaj.http.HttpResponse[String] = HttpResponse(,404,Map(Content-Length -> Vector(0), Date -> Vector(Tue, 26 Jul 2016 17:53:49 GMT), Server -> Vector(Apache-Coyote/1.1), Status -> Vector(HTTP/1.1 404 Not Found))) 
+0

我才意識到你用不同的網址,用一個參數調用。爲什麼? – Marco

+0

你釘了它我搞砸了/ api不知道爲什麼我跳過它,猜測一整天的編碼。 – theMadKing

回答

1

我認爲這個問題是你沒有正確初始化爲params功能Map[String,String]參數。初始化地圖的正確方法是:

val myMap = Map(key -> value, key2 -> value2) 

所以你的GET請求會是這樣的:

val result = Http("http://xxxxxx:9000/parameter/value").params(Map("ecosystem_name"-> "streaming_pipeline", "ecosystem_key_name"-> "kafka_brokers")).asString 
+0

添加了一個編輯錯誤仍在生成。 – theMadKing