I
I
Ivan Smirnov2015-03-13 16:53:48
Scala
Ivan Smirnov, 2015-03-13 16:53:48

How to send a get request using play framework ws without doing url encode?

Hello! Now I am engaged in the integration of our project on Play 2.3.8 and gis.
With gis, communication occurs with the help of get requests.
Here is a correct example of a request to get an object:

http://myGisServer.ru/myservice?token=XYZ%3D&query=[{"id":"123","objectIds":["5"]}]

Where token is the token received during authorization and over which url encode is performed.
And query, respectively, the request in the form of json
I tried to implement it like this:
def getPoint = Action.async{
  val data = Json.obj(
      "id" -> "123",
      "objectIds" -> Json.arr("5")
  )
  val ws = WS.url("http://myGisServer.ru/myservice").withQueryString(
    "token" -> currentToken,
    "query" -> data.toString()
  )
  val futureResponse: Future[WSResponse] = ws.get()
  futureResponse.map(response => {
    Ok(response.json)
  })
}

But, this does not work, because ws automatically produces url encode over the entire request, and over the json part, encode is not necessary.
Forming a string and just feeding it to ws as a url doesn't work either, because ws can't accept some characters in a url, including spaces and square brackets.
How can I remove encode from the request part, or create a request without encode at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2015-03-13
@mrRontgen

Through play WS there is no way. It uses com.ning.http.client.RequestBuilderBase and encodes the request in this method .
Try to implement your RequestBuilder ) which won't encode.

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question