public static String addParam ( String url , String name , String value , String charset ) throws UnsupportedEncodingException { StringBuilder newUrl = new StringBuilder ( url ) ; if ( ! url . endsWith ( "?" ) && ! url . endsWith ( "&" ) ) { if ( url . contains ( "?" ) ) { newUrl . append ( ' ' ) ; } else { newUrl . append ( ' ' ) ; } } newUrl . append ( URLEncoder . encode ( name , charset ) ) ; newUrl . append ( ' ' ) ; newUrl . append ( URLEncoder . encode ( value , charset ) ) ; return newUrl . toString ( ) ; }
Adds a query string param to the URL adding a ? if there s no query string yet .