Friday, February 17, 2012

How do you encode URL in android?


Encoding URL is very straightforward, simply call the encode method of the URLEncoder class on the String data that you want to encode.
try {  
      String url = "http://www.yoursite.com/blah";
      String queryString = "param=1&value=2";  
     String encodedQueryString = URLEncoder.encode(queryString,"UTF-8");

     encodedUrl = url + "?" + encodedQueryString;
     
       Log.d("Enc URL: " + encodedurl);
     }
     catch (UnsupportedEncodingException e)
     {
      Log.e("Exception: " + e.getMessage());
     
    }

No comments:

Post a Comment