Friday, July 27, 2012

Java: Como codificar una URL en UTF-8

Existe una forma muy simple para codificar un String de URL en UTF-8:

 try{
   String encodedurl = URLEncoder.encode(url.toString(),"UTF-8"); 
   System.out.println(encodedurl);
  }catch(UnsupportedEncodingException e){
   System.err.println(e);
  }

Al método donde agreguen estas lineas deberán agregar

   throws UnsupportedEncodingException

Bookmark and Share
Related Posts Plugin for WordPress, Blogger...