- 编写通用的发送方法:
public static String executeGet(String url){
Log.info(url);
HttpClient client = new HttpClient();
GetMethod getM = null;
String responseString = "";
try {
getM = new GetMethod(url);
getM.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
client.executeMethod(getM);
Reader reader = new InputStreamReader(getM.getResponseBodyAsStream(),"utf8");
BufferedReader br = new BufferedReader(reader);
StringBuffer buf = new StringBuffer();
String line = "";
while (null != (line = br.readLine())) {
buf.append(line);
}
responseString = buf.toString();
Log.info(responseString);;
} catch (Exception e1) {
e1.printStackTrace();
} finally {
getM.releaseConnection();
}
return responseString;
}
- 编写推送数据的接口及实现
public static boolean pushUserInfoToAPP(JSONObject jo){
String phone = jo.getString("phone");
String name = jo.getString("name");
String appType = jo.getString("appType");
StringBuffer url = new StringBuffer(PropertiesReader.getProp("URL_USER"));
String result = null;
try {
url.append("/service/AddPatientInfo")
.append("/").append(phone)
.append("/").append(phone+"@139.com")
.append("/").append(URLEncoder.encode(name,"UTF-8"))
.append("/").append(1)
.append("/").append("1970-01-01")
.append("/").append("CMRI")
.append("/").append(appType);
result = HttpClientExecute.executeGet(url.toString());
} catch (Exception e) {
e.printStackTrace();
}
}