简体   繁体   中英

making a GET request to a webservice from the playframework 2.0

I'm trying to call a webservice from the play framework, and I think I'm doing it wrong. I have an example call to http://www.myweather2.com/developer/forecast.ashx?uac=eDKGlpcBQN&query=52.6%2C-4.4&output=xml

A snippet from what I'm trying from the playframework is the following:

val response = WS.url("http://www.myweather2.com/developer/forecast.ashx?uac=eDKGlpcBQN&query=52.6%2C-4.4&output=xml").get.get()
val body = response.getBody

When I call this, the body consists of "useraccount does not exist". When I just put this url in a browser, I get the response I'm looking for. What am I doing wrong here?

For some reason, I was getting WS from the wrong import. When I fixed the imports to import play.api.libs.ws.WS , it worked. I'm still amazed it worked halfway with the wrong import

I know this is old, but I just solved this problem while trying to do the same thing - getting the same results.

GET variables must be passed with WS.url("http://...").setQueryParameter(key, value)

Example:

val promise = WS.url("http://www.myweather2.com/developer/forecast.ashx").setQueryParameter("uac", "eDKGlpcBQN").setQueryParameter("query", "52.6%2C-4.4").setQueryParameter("output", "xml").get()

Annoying, but a relatively simple fix.

Don't know about "useraccount does not exist" but this seems to work:

  val promise = WS.url("http://www.myweather2.com/developer/forecast.ashx?uac=eDKGlpcBQN&query=52.6%2C-4.4&output=xml").get()
  val body = promise.value.get.body

Edit: Removed the space.

Also make sure your editor is not inserting a \\n or \\r after ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM