1.请求restful接口
请求restful接口分为两种,要看对方发布的接口请求参数是什么类型。
第一种:参数为String类型,直接采用httpClient post请求就可以了;
String url = "http://127.0.0.1:8480/jkcsYsd/test";
HttpClient httpclient = new HttpClient();
// 发送接口
PostMethod post = new PostMethod(url);
post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
post.addParameter("id", "228457");
httpclient.executeMethod(post);
String info = new String(post.getResponseBody(), "utf-8");
System.out.println(info);
第二种:参数是json 类型,采用封装的URLConnection方式;
String url = "http://127.0.0.1:8480/jkcsYsd/queryFwbByUserInfo";
String data ="{\"userid\":\"YLJG_5bcd1318-3074-11e7-bfe3-00163e0e1cc6\"}";
URL weburl = new URL(url);