0

I am trying to exectue the following REST url using Android but I get the following error,

11-23 12:12:32.749: E/AndroidRuntime(709): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 121: http://xxxxxxxxxxxxxxxxx.com/add.php?key=xxxxxxxxxxxx&type=Timbuktu&description=Africa&latitude=16.776767&longitude=-3.006361&private={"tag":"test"}

When I call the same URL in a browser, it works. Any help would be apprciated !

TomSelleck
  • 6,706
  • 22
  • 82
  • 151

3 Answers3

4

Encode your url first, paramerters part only..

 URLEncoder.encode("key=xxxx&type=Timbuktu&description=Africa&latitude=16.776767&longitude=-3.006361&private={\"tag\":\"test\"}", "UTF-8")
Nermeen
  • 15,883
  • 5
  • 59
  • 72
  • Hey, I'm just trying this now but keep getting, {"status":"error","message":"Missing type parameter in http request"} back from the server. – TomSelleck Nov 23 '12 at 13:13
2

You need to URL-encode the parameters of your URL, like this:

String privateParamValue = URLEncoder.encode("{\"tag\":\"test\"}", "UTF-8");
String url = "http://xxxx.com/add.php?key=xxxx&type=Timbuktu&description=Africa&latitude=16.776767&longitude=-3.006361&private=" + privateParamValue;
sdabet
  • 18,360
  • 11
  • 89
  • 158
1

Browsers are intelligent and encode the URL in UTF-8. I Think u should also do that at client end.

URLEncoder.encode(url, "UTF-8");
Talha Ahmed Khan
  • 15,043
  • 10
  • 42
  • 49