java版本代码
//传入拼接好的xml字符串
public String addOrUpdateBill(String xml){
Logger.error("输入参数xml:" + xml);
String result = null;
String url = getUrl("datasource");//获取需要的参数
Logger.error("url:" + url);
if (url == null) {
Logger.error("获取url地址错误");
url = "http://127.0.0.1:99/service/XChangeServlet?account=develop&groupcode=01";//根据实际需求修改
}
URL realURL;
try {
realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection) realURL.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("content-type", "dept/xml");
connection.setRequestMethod("POST");
StringReader sr = new StringReader(xml);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(is);
// 设定格式
XMLOutputter out = new XMLOutputter();
Logger.error("processing completed,ready to send data to url:"+ url);
out.output(new DOMBuilder().build(doc),connection.getOutputStream());
Logger.error("send success");
// 从连接的输入流中取得回执信息
InputStream inputStream = connection.getInputStream();
result = IOUtils.toString(inputStream, "UTF-8");
Logger.error("result:" + result);
}
-----------------------------
String res = (result.split("<resultcode>")[1].split("<"))[0]; if(res.equals("1")){ //...成功之后的逻辑 }else{ //...失败之后的逻辑 }
参考:https://blog.csdn.net/kon_mio/article/details/107069607?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control
原文链接:https://blog.csdn.net/kon_mio/article/details/107069607