httpClient post请求


String url = "请求地址";
//创建post对象
HttpPost httpPost = new HttpPost(url);
//创建json用来传参数
JSONObject postData = new JSONObject();

postData.put("data", eString.toString());
//拿到参数
httpPost.setEntity(new StringEntity(postData.toString(), HTTP.UTF_8));
//创建实例
DefaultHttpClient httpClient = null;
httpClient = new DefaultHttpClient();
//发送post请求
HttpResponse httpResponse = httpClient.execute(httpPost);
//输出请求状态码
System.out.println(httpResponse.getStatusLine().getStatusCode());
//返回结果
String result = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
//输出结果
System.out.println(result);

 

你可能感兴趣的:(httpClient)