Android URL Encode encodeParameters(Map params)

Here you can find the source of encodeParameters(Map params)

Description

encode Parameters

License

Open Source License

Declaration

public static String encodeParameters(Map<String, String> params)
            throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/* /* www  .  j  a va 2  s.  c o m*/
 * SWRVE CONFIDENTIAL
 * 
 * (c) Copyright 2010-2014 Swrve New Media, Inc. and its licensors.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is and remains the property of Swrve
 * New Media, Inc or its licensors.  The intellectual property and technical
 * concepts contained herein are proprietary to Swrve New Media, Inc. or its
 * licensors and are protected by trade secret and/or copyright law.
 * Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Swrve.
 */

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import java.util.Iterator;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    private static final String CHARSET = "UTF-8";

    public static String encodeParameters(Map<String, String> params)
            throws UnsupportedEncodingException {
        StringBuilder body = new StringBuilder();
        Iterator<Entry<String, String>> it = params.entrySet().iterator();
        boolean firstElement = true;
        while (it.hasNext()) {
            Map.Entry<String, String> pair = it.next();
            if (firstElement) {
                firstElement = false;
            } else {
                body.append("&");
            }
            body.append(URLEncoder.encode(pair.getKey(), CHARSET)
                    + "="
                    + ((pair.getValue() == null) ? "null" : URLEncoder
                            .encode(pair.getValue(), CHARSET)));
        }
        return body.toString();
    }
}

Related

  1. encodeUrl(Bundle parameters)
  2. encodeUrlParam(String s)
  3. weakUrlEncode(String url)
  4. encode(String s)
  5. getParams(Map params, String encode)
  6. escapeURL(String link)