Back to project page FrameLite.
The source code is released under:
GNU General Public License
If you think the Android project FrameLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.miku.framelite.utils; /*from w w w . ja va2 s . c o m*/ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.CharsetEncoder; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; public class HttpUtils { /** * ?{@code Map<String, String>}?????{@code List<NameValuePair>} * @param postParams * @return */ public static List<NameValuePair> buildPostParams(Map<String, String> postParams) { List<NameValuePair> result = new ArrayList<NameValuePair>(postParams.size()); for (String key : postParams.keySet()) { result.add(new BasicNameValuePair(key, postParams.get(key))); } return result; } /** * ?{@code Map<String, String>}?????{@code String}<br/> * ?{@code username=abc&password=123} * @param getParams * @return */ public static String buildGetParams(Map<String, String> getParams){ StringBuilder sb=new StringBuilder(); for (String key : getParams.keySet()) { try { sb.append(key).append("=").append(URLEncoder.encode(getParams.get(key),"UTF-8") ).append('&'); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(sb.charAt(sb.length()-1)=='&'){ sb.deleteCharAt(sb.length()-1); } return sb.toString(); } }