当前位置:   article > 正文

java post请求 application/xml方式

java post请求 application/xml方式
  1. //java post请求 xml
  2. try {
  3. String cdnaddress = ConfigUtil.getConfig("cdnaddress");
  4. URL wsUrl = new URL(cdnaddress);
  5. HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
  6. conn.setDoInput(true);//有输入
  7. conn.setDoOutput(true);//有输出
  8. conn.setRequestMethod("POST");
  9. conn.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
  10. //从配置文件取得信息
  11. String correlateID = correlateid;
  12. String r = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"+
  13. "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"+
  14. "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> \n"+
  15. "<soapenv:Body> \n"+
  16. "<ns1:ContentDeployReq \n"+
  17. "soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"+
  18. " xmlns:ns1=\"iptv\"> \n"+
  19. "<CMSID xsi:type=\"xsd:string\">" + cmsid +"</CMSID> \n"+
  20. "</ns1:ContentDeployReq> \n"+
  21. "</soapenv:Body> \n"+
  22. "</soapenv:Envelope>";
  23. OutputStream os = conn.getOutputStream();
  24. os.write(r.getBytes());
  25. InputStream is = conn.getInputStream();
  26. byte[] b = new byte[1024];
  27. int len = 0;
  28. String s1 = "";
  29. while( (len = is.read(b)) != -1){
  30. s1 += new String(b,0,len,"UTF-8");
  31. }
  32. logger.info("通知CDN:"+s1);
  33. os.close();
  34. is.close();
  35. conn.disconnect();
  36. }
  37. catch (Exception e) {
  38. e.printStackTrace();
  39. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/790901
推荐阅读
相关标签
  

闽ICP备14008679号