private static String doFormUrlEncode(final NameValuePair[] pairs,final String charset) throws UnsupportedEncodingException {
  final StringBuffer buf=new StringBuffer();
  for (int i=0; i < pairs.length; i++) {
    final URLCodec codec=new URLCodec();
    final NameValuePair pair=pairs[i];
    if (pair.getName() != null) {
      if (i > 0) {
        buf.append("&");
      }
      buf.append(codec.encode(pair.getName(),charset));
      buf.append("=");
      if (pair.getValue() != null) {
        buf.append(codec.encode(pair.getValue(),charset));
      }
    }
  }
  return buf.toString();
}

private static String doFormUrlEncode ( final NameValuePair [ ] pairs , final String charset ) throws UnsupportedEncodingException { final StringBuffer buf = new StringBuffer ( ) ; for ( int i = 0 ; i < pairs . length ; i ++ ) { final URLCodec codec = new URLCodec ( ) ; final NameValuePair pair = pairs [ i ] ; if ( pair . getName ( ) != null ) { if ( i > 0 ) { buf . append ( "&" ) ; } buf . append ( codec . encode ( pair . getName ( ) , charset ) ) ; buf . append ( "=" ) ; if ( pair . getValue ( ) != null ) { buf . append ( codec . encode ( pair . getValue ( ) , charset ) ) ; } } } return buf . toString ( ) ; }
form - urlencoding routine . the default encoding for all forms is ` application / x - www - form - urlencoded ' . a form data set is represented in this media type as follows : the form field names and values are escaped : space characters are replaced by ` + ' , and then reserved characters are escaped as per [ url ] ; that is , non - alphanumeric characters are replaced by ` % hh ' , a percent sign and two hexadecimal digits representing the ascii code of the character . line breaks , as in multi - line text field values , are represented as cr lf pairs , i . e . ` % 0d % 0a ' .
