Parse a x-www-form-urlencoded string : URLEncoder « Network Protocol « Java

Parse a x-www-form-urlencoded string



public class Main {
  public static void main(String[] argv) throws Exception {
    String line = URLEncoder.encode("name1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");

    String[] pairs = line.split("\\&");
    for (int i = 0; i < pairs.length; i++) {
      String[] fields = pairs[i].split("=");
      String name = URLDecoder.decode(fields[0], "UTF-8");
      String value = URLDecoder.decode(fields[1], "UTF-8");


Related examples in the same category

1.URL Encoder: similar to the class
2.Decoding and encoding URLs
3.URL Encoder: Encode a string according to RFC 1738.
4.Encode a path as required by the URL specification
5.Calls, String) via reflection, if we are running on JRE 1.4 or later, otherwise reverts to the deprecated URLEncoder.encode(String)method.
6.Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding.
7.Provides a method to encode any string into a URL-safe form
8.Converts a String SJIS or JIS URL encoded hex encoding to a Unicode String
9.Request parsing and encoding utility methods