[Java] webservice中http拼接方式 →→→→→进入此内容的聊天室

来自 , 2020-04-08, 写在 Java, 查看 98 次.
URL http://www.code666.cn/view/365d1777
  1. //http拼接方式
  2.         private Message sendNew(String method,String userName,String title,String content,String tel){
  3.                 Message result = new Message();
  4.                 try {
  5.                 //判断是否是自定义手机号码
  6.                         JSONObject obj=new JSONObject();
  7.                         if(tel!= null ||!"".equals(tel) ){
  8.                                 obj.put("mobiles",tel);
  9.                         }
  10.                         obj.put("emsEnterpriseID","111");
  11.                         obj.put("emsLoginName","111");
  12.                         obj.put("emsPassword",MD5.toMD5("123456"));
  13.                        
  14.                         DefaultHttpClient httpClient = new DefaultHttpClient();
  15.                         String soapRequestData = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""
  16.                                 + " xmlns:ser=\"http://service.msgbuss.ceair.com/\">"
  17.                             +"<soapenv:Header/>"
  18.                             +"<soapenv:Body>"
  19.                               +"<ser:send>"
  20.                                  +"<messageRequestVO>"
  21.                                          +"<bizProduct>"+method+"</bizProduct>"
  22.                                          +"<content>"+content+"</content>"
  23.                                          +"<extention>"+obj.toString()+"</extention>"
  24.                                          +"<requestId>"+UUID.randomUUID().toString()+"</requestId>"
  25.                                          +"<title>"+title+"</title>"
  26.                                          +"<toUserId>"+userName+"</toUserId>"
  27.                                  +"</messageRequestVO>"
  28.                                    +"</ser:send>"
  29.                             +"</soapenv:Body>"
  30.                             +"</soapenv:Envelope>";
  31.                                
  32.                                 HttpPost httppost = new HttpPost("http://xxx.xx.x.x:8080/msgbuss/soap/sendMessage?wsdl");
  33.                                 try {
  34.                                         HttpEntity re = new StringEntity(soapRequestData,HTTP.UTF_8);
  35.                                         httppost.setHeader("Content-Type","application/soap+xml; charset=utf-8");
  36.                                         httppost.setEntity(re);
  37.                                         HttpResponse response = httpClient.execute(httppost);
  38.                                         String str = EntityUtils.toString(response.getEntity());
  39.                                         result.setResultCode(str.substring(str.indexOf("<resultCode>")+12,str.indexOf("</resultCode>")));
  40.                                         result.setMsg(str.substring(str.indexOf("<desc>")+6,str.indexOf("</desc>")));
  41.                                         result.setSuccess(Boolean.parseBoolean(str.substring(str.indexOf("<success>")+9,str.indexOf("</success>"))));
  42.                                         return result;
  43.                                 } catch (UnsupportedEncodingException e) {
  44.                                         e.printStackTrace();
  45.                                 } catch (ClientProtocolException e) {
  46.                                         e.printStackTrace();
  47.                                 } catch (IOException e) {
  48.                                         e.printStackTrace();
  49.                                 }finally{
  50.                                         httpClient.getConnectionManager().shutdown();
  51.                                 }
  52.                                 return result;
  53.                 } catch (Exception e) {
  54.                         result.setSuccess(false);
  55.                         result.setMsg("系统异常");
  56.                 }
  57.             return  result;
  58.         }

回复 "webservice中http拼接方式"

这儿你可以回复上面这条便签

captcha