标签:
public static String post(String interfaceType, JSONObject json) { String data = null; HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); StringBuilder builder = new StringBuilder(); String url_params = String.format(HttpConst.URL, interfaceType, jsonToParams(json)); //HttpPost post = new HttpPost(url_params); HttpGet get=new HttpGet(url_params); try { HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); for (String s = reader.readLine(); s != null; s = reader.readLine()) { builder.append(s); } data = JSONTokener(builder.toString()); } catch (Exception e) { LogUtils.d(e); } return data; } public static String jsonToParams(JSONObject json) { String params = json.toString(); params = params.replace("}", ""); params = params.replace("{", ""); params = params.replace("\"", ""); params = params.replace(":", "="); String[] strings = params.split(","); params = ""; for (int i = 0; i < strings.length; i++) { params += strings[i] + "&"; } return params.substring(0, params.length() - 1); }
标签:
原文地址:http://www.cnblogs.com/g-sheng/p/5440029.html