日期:2014-05-20 浏览次数:21068 次
public static String post(String url,String json) { /* HTTP Post */ HttpPost httpRequest = new HttpPost(url); // param NameValuePair[] // request.getParameter("name") List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("jsonParameter", json)); try { // HTTP request httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); // HTTP response defaultHttpClient = new DefaultHttpClient(); [color=#FF0000]HttpResponse httpResponse = defaultHttpClient.execute(httpRequest);[/color] // 200 ok if (httpResponse.getStatusLine().getStatusCode() == 200) { result= EntityUtils.toString(httpResponse .getEntity()); return result; } } catch (ClientProtocolException e) { e.printStackTrace(); return null; } return result; }