Question

In my Android project I'm using Robospice with spring-android. Which works fine for all REST communication. But for the below request query parameter "=" is getting converted to "&". Because of this the request is getting failed.

Query String: tags=["keywords:default=hello"]

By checking the logs the request is converted as below for making call by the library.

http://XXX/rest/media/search?token=123&tags=%5B%22keywords:default&hello%22%5D

here "=" sign is converted to "&" in "keywords:default=hello"

Request Class

here tags = String.format("[\"keywords:default=%s\"]", mTag);

@Override
public MVMediaSearch loadDataFromNetwork() throws Exception
{ 
  String search=""; 
  if(!tags.equals(Constants.EMPTY_DATA)) 
    search="&tags="+tags;
  return   getRestTemplate().getForObject( Constants.BASE_URL+"/media/search?token="+token+search, MVMediaSearch.class ); 
}

If I fire the URL in a browser, I'm getting error. And if I change the '&' sign to its corresponding url encoded value in browser, it works fine.

Était-ce utile?

La solution

I also have the same issue. For alternative, I use getForObject(java.net.URI, java.lang.Class).

URI uri = new URI(Constants.BASE_URL+"/media/search?token="+token+search);
getRestTemplate().getForObject(uri, MVMediaSearch.class );

http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/client/RestTemplate.html#getForObject(java.net.URI, java.lang.Class)

Autres conseils

You can do something like this:

URI uri = new URI(
    "http",
    Constants.BASE_URL, 
    "/media/search?token=", 
    token,
    search,
    null);
String request = uri.toASCIIString();

take a look at THIS and see if you understand (you have to adapt to your code - this is not completely done for you)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top