HttpURLConnection
package com.sinosoft.sms;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* ����ƽ̨���Ͷ��Ź�����
* @author cuiwenbo
*
*/
public class SendMessageUtil {
public String sendMessage(String sendXmlInfo) throws IOException{
String result = "";
String webServiceAddr = "http://10.163.90.120:8080/GeneralSMS/ws/smsInterface";
// URL url = new URL(WEB_SERVICE_ADDR);
URL url = new URL(webServiceAddr);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
printWriter.write(sendXmlInfo);
// flush���������
printWriter.flush();
//��ʼ��ȡ����
BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// BufferedWriter bw = new BufferedWriter(out)
StringBuffer sb = new StringBuffer();
String ss = "";
while((ss=br.readLine())!=null){
sb.append(ss);
}
System.out.println("****"+sb.toString()+"*****");
// int len;
// byte[] arr = new byte[1024];
// while((len=bis.read(arr))!= -1){
// bos.write(arr,0,len);
// bos.flush();
// }
// bos.close();
// result = bos.toString();
// System.out.println(result);
return result;
}
/**
* @Description�� ���Ͷ��������ܽ���ƽ̨��POST������
* @Author�� zhouzhiwei
* @CraterDate�� 2020/2/19
* @param url ���ܽ���ƽ̨��ַ
* @param params ���������json���ͣ�
* @Return�� java.lang.String
*/
public static String clusterSend(String url, String params) {
return HttpClientUtil.doPost(url, params);
}
public static void main(String[] args) throws Exception {
// String url = "https://iip-uat.evergrandelife.com.cn/api/proxy-service/message/send";
// EskMessageInfo eskMessageInfo = new EskMessageInfo();
// eskMessageInfo.setSystemId("100101");
// eskMessageInfo.setMobile("123456");
// eskMessageInfo.setText("");
// String s = JSONObject.toJSONString(eskMessageInfo);
// System.out.println(s);
// String s = "{\"mobile\":\"123456\",\"systemId\":\"100101\",\"text\":\"\"}";
// JSONObject jo = JSONObject.parseObject(s);
// System.out.println(jo.toJSONString());
// System.out.println(jo.getString("mobile"));
// System.out.println(jo.getString("systemId"));
// System.out.println(jo.getString("text"));
// String param = "{\"mobile\":\"13012343333\",\"sendTime\":\"\",\"systemId\":\"100201\",\"templateId\":\"T00139\",\"text\":\"��������١��Ĺ�������ã���л��ѡ��������Ϊ����ѡ���ؼ���ͨ��������ʹ�ã����ע������ٹٷ��š�������ٷ������ġ������ɺ������ָ��������Ϊ���ṩ������������ѯ���ķ�����Ա��ͷ�����4006368888����л���Ժ�����ٵ�֧�֣�ף��������죡\"}";
// String result = SendMessageUtil.clusterSend(url, param);
// System.out.println(result);
}
}

浙公网安备 33010602011771号