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 !

1
  • 1
    URLEncoder.encode(url, "UTF-8"); Commented Nov 23, 2012 at 12:24

3 Answers 3

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")
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, I'm just trying this now but keep getting, {"status":"error","message":"Missing type parameter in http request"} back from the server.
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;

Comments

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.