Here you can find the source of encodeDataPair(final StringBuilder buffer, final String key, final String value)
Encode a key/value data pair to be used in a HTTP post request.
Parameter | Description |
---|---|
buffer | a parameter |
key | a parameter |
value | a parameter |
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException
//package com.java2s; import java.io.*; import java.net.URLEncoder; public class Main { /**/*from w ww.j a v a 2 s . c om*/ * <p>Encode a key/value data pair to be used in a HTTP post request. This * INCLUDES a & so the first key/value pair MUST be included manually, * e.g:</p> * <code> * StringBuffer data = new StringBuffer(); * data.append(encode("guid")).append('=').append(encode(guid)); * encodeDataPair(data, "version", description.getVersion()); * </code> * * @param buffer * @param key * @param value * @return */ private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException { buffer.append('&').append(encode(key)).append('=').append(encode(value)); } /** * Encode text as UTF-8 * * @param text * @return */ private static String encode(String text) throws UnsupportedEncodingException { return URLEncoder.encode(text, "UTF-8"); } }