public static void main(String[] args) throwsException {//DoGet(String url)
String resultGet = DoGet("http://localhost:14248/api/Report/GetTest?parentid=40");//DoPost(String url,List nvps)
List nvps = new ArrayList();
nvps.add(new BasicNameValuePair("parentid", "40"));
String resultPost= DoPost("http://localhost:14248/api/Report/PostTest",nvps);//DoPost(String url, JSONObject template)
JSONObject template = newJSONObject();
template.put("data",data);
String json=HttpWebapi.DoPost(urlString,template);//DoPost(String url, String json)
SysUser user=newSysUser();
user.setAccount(etAccount.getText().toString());
user.setPassword(etPwd.getText().toString());
ApiRequest request=new ApiRequest<>();
request.setData(user);
String data=JsonConvert.toJSON(request);String json= HttpWebapi.DoPost(AppConfig.getUrl() + "api/user/login", data);
}public static String DoGet(String url) throwsException {
HttpGet httpGet= newHttpGet(url);
HttpClient client= newDefaultHttpClient();
HttpResponse resp=client.execute(httpGet);
HttpEntity he=resp.getEntity();
String respContent= EntityUtils.toString(he, "UTF-8");returnrespContent;
}public static String DoPost(String url,List nvps) throwsException {
HttpPost httpost= newHttpPost(url);
HttpClient client= newDefaultHttpClient();
httpost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
HttpResponse resp=client.execute(httpost);
HttpEntity he=resp.getEntity();
String respContent= EntityUtils.toString(he, "UTF-8");returnrespContent;
}public static String DoPost(String url, JSONObject template)throwsException{
HttpClient httpClient= newDefaultHttpClient();
HttpPost httpPost= newHttpPost(url);
httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json");
httpPost.setEntity(new StringEntity(template.toString(),"utf-8"));
HttpResponse resp=httpClient.execute(httpPost);
String respContent= EntityUtils.toString(resp.getEntity(), "UTF-8");returnrespContent;
}public static String DoPost(String url, String json) throwsException{
HttpClient httpClient= newDefaultHttpClient();
HttpPost httpPost= newHttpPost(url);
httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json");
httpPost.setEntity(new StringEntity(json,"utf-8"));
HttpResponse resp=httpClient.execute(httpPost);
String respContent= EntityUtils.toString(resp.getEntity(), "UTF-8");returnrespContent;
}