Java Code Examples for org.apache.http.message.BasicNameValuePair#getName()

The following examples show how to use org.apache.http.message.BasicNameValuePair#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpHelper.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTTP上传参数字符串
 *
 * @param param          上传参数list
 * @param isCheckChinese 是否检查中文字符
 * @return String
 */
public static String getParamContent(List<BasicNameValuePair> param, boolean isCheckChinese) {
    LogHelper.d(TAG, "--> getParamContent");
    StringBuilder sb = new StringBuilder();
    boolean isFirst = true;
    for (BasicNameValuePair pair : param) {
        String key = pair.getName();
        String value = pair.getValue();
        if (StringHelper.isEmptyString(value)) {
            value = "null";
        } else if (isCheckChinese) {
            if (StringHelper.hasChinese(value)) {
                try {
                    value = URLEncoder.encode(value, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        }
        if (isFirst) {
            sb.append(key).append("=").append(value);
            isFirst = false;
        } else {
            sb.append("&").append(key).append("=").append(value);
        }
    }
    return sb.toString();
}
 
Example 2
Source File: HttpHelper.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTTP上传参数字符串
 *
 * @param param          上传参数list
 * @param isCheckChinese 是否检查中文字符
 * @return String
 */
public static String getParamContent(List<BasicNameValuePair> param, boolean isCheckChinese) {
    LogHelper.d(TAG, "--> getParamContent");
    StringBuilder sb = new StringBuilder();
    boolean isFirst = true;
    for (BasicNameValuePair pair : param) {
        String key = pair.getName();
        String value = pair.getValue();
        if (StringHelper.isEmptyString(value)) {
            value = "null";
        } else if (isCheckChinese) {
            if (StringHelper.hasChinese(value)) {
                try {
                    value = URLEncoder.encode(value, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        }
        if (isFirst) {
            sb.append(key).append("=").append(value);
            isFirst = false;
        } else {
            sb.append("&").append(key).append("=").append(value);
        }
    }
    return sb.toString();
}
 
Example 3
Source File: HttpUtils.java    From odo with Apache License 2.0 5 votes vote down vote up
public static String doProxyGet(String url, BasicNameValuePair[] data) throws Exception {
    String fullUrl = url;

    if (data != null) {
        if (data.length > 0) {
            fullUrl += "?";
        }

        for (BasicNameValuePair bnvp : data) {
            fullUrl += bnvp.getName() + "=" + uriEncode(bnvp.getValue()) + "&";
        }
    }

    HttpGet get = new HttpGet(fullUrl);
    int port = Utils.getSystemPort(Constants.SYS_HTTP_PORT);
    HttpHost proxy = new HttpHost("localhost", port);
    HttpClient client = new org.apache.http.impl.client.DefaultHttpClient();
    client.getParams().setParameter(org.apache.http.conn.params.ConnRoutePNames.DEFAULT_PROXY, proxy);
    HttpResponse response = client.execute(get);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String accumulator = "";
    String line = "";
    Boolean firstLine = true;
    while ((line = rd.readLine()) != null) {
        accumulator += line;
        if (!firstLine) {
            accumulator += "\n";
        } else {
            firstLine = false;
        }
    }
    return accumulator;
}