我有一个RESTful应用编程接口调用,如下所示:
http://xxxxx:9000/api/parameter/value?ecosystem_name=streaming_pipeline&ecosystem_key_name=kafka_brokers当我通过邮递员或Swagger使用它时,它工作得很好。当我在上面运行scalaj-http时:
val result = Http("http://xxxxxx:9000/parameter/value").params(Map(("ecosystem_name", "streaming_pipeline"), ("ecosystem_key_name", "kafka_brokers"))).asString我得到了一个not found响应。当我只使用一个参数时,这对其他调用也有效:
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)))发布于 2016-07-26 08:04:05
我认为问题在于您没有正确地初始化params函数的Map[String,String]参数。初始化Map的正确方法是:
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")).asStringhttps://stackoverflow.com/questions/38578977
复制相似问题