Java URL Parameter Builder mapToFormString(Map map)

Here you can find the source of mapToFormString(Map map)

Description

map To Form String

License

Open Source License

Declaration

private static String mapToFormString(Map<String, String> map) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URLEncoder;

import java.util.Map;

public class Main {
    private static String mapToFormString(Map<String, String> map) {
        StringBuilder postDataStringBuilder = new StringBuilder();

        String postDataString;//from w w  w .jav  a  2  s. co m

        try {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                postDataStringBuilder.append(URLEncoder.encode(entry.getKey(), "UTF-8")).append("=")
                        .append(URLEncoder.encode(entry.getValue(), "UTF-8")).append("&");
            }
        } catch (Exception e) {
        } finally {
            postDataString = postDataStringBuilder.toString();
        }
        return postDataString;
    }
}

Related

  1. getUrlParameters(String url)
  2. getUrlParameters(String url)
  3. getURLParameters(URI uri)
  4. map2String(Map params)
  5. mapToFormEncodedString(Map data)
  6. mapToStr( Map map)
  7. mapToStr(Map map)
  8. mapToString(Map map)
  9. parse(final Map> parameters, final Scanner scanner, final String encoding)