0

I am having the following url, which was using in my application

url = "http://ip/somefile.py?name=Adithya g&age=15&address=Trichy Tamilnadu"

when i am going to parse the above string in either httpget or httppost using android. I am getting error. suppose if the url is modified as the following

url  ="http://ip/somefile.py?name=Adithya%20g&age=15&address=Trichy%20Tamilnadu"

the url is working fine. Where was the mistake? whether it is mistake of that particular server or the android development side.

Tortoise Walker
  • 61
  • 2
  • 10

1 Answers1

1

You should in fact URLEncode the "invalid" characters.For more info see Url encoding in Android

Or use like

   String url = Uri.parse("http://ip/somefile.py")
                    .buildUpon()
                    .appendQueryParameter("key", "val")
                    .build().toString();

Where key= parameter name, val = parameter value.

Or this Android: howto parse URL String with spaces to URI object?

Community
  • 1
  • 1
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
  • I didn't know about URLEncoder, in my app I naively did String querystring="some string with space" and then did querystring=querystring.replace(" ", "%20"); This seems like a much more complete and trustable approach. +1d But what could be possible drawbacks of my method compared to this? – Kartik_Koro Jul 10 '14 at 07:14
  • 1
    You should use the URLEncoder class, to encode the params you want to pass with your URL. Just replacing the spaces isn't the best idea and should not even be suggested. – Shivam Verma Jul 10 '14 at 07:48