-- Encode a URL --




import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;

public final class TestURLEncode{

public static void main( String[] args ) throws URISyntaxException, MalformedURLException{

// reserved chars that are not escaped in URLs include:
// ; / ? : @ & = + $ ,

URI uri = new URI( "http", "//www.example.com/you & I 10%? weird & weirder neé", null );
System.out.println( uri.toURL().toString() );

// prints http://www.example.com/you%20&%20I%2010%25?%20wierd%20&%20wierder%20neé
// note how it fails to encode é
}
}

Comments

Popular posts from this blog

-- Are you a Android Developer? --

-- Google Android --

What is serialVersionUID?