Android URL Encode getParams(Map params, String encode)

Here you can find the source of getParams(Map params, String encode)

Description

get Params

Declaration

public static String getParams(Map<String, String> params, String encode) 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import java.util.Map;

public class Main {

    public static String getParams(Map<String, String> params, String encode) {
        StringBuffer stringBuffer = new StringBuffer();
        if (params != null && !params.isEmpty()) {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                try {
                    if (entry.getValue() == null
                            || "".equals(entry.getValue())) {
                        stringBuffer.append(entry.getKey()).append("=")
                                .append(entry.getValue()).append("&");
                    } else {
                        stringBuffer//from  ww  w  .  j a v  a 2 s.co m
                                .append(entry.getKey())
                                .append("=")
                                .append(URLEncoder.encode(entry.getValue(),
                                        encode)).append("&");
                    }
                } catch (UnsupportedEncodingException e) {
                    stringBuffer = null;
                }
            }
            if (stringBuffer != null) {
                stringBuffer.deleteCharAt(stringBuffer.length() - 1);
            }
        }
        return stringBuffer.toString();
    }
}

Related

  1. encodeUriSegment(String segment)
  2. encodeUrl(Bundle parameters)
  3. encodeUrlParam(String s)
  4. weakUrlEncode(String url)
  5. encode(String s)
  6. encodeParameters(Map params)
  7. escapeURL(String link)