以下引用《misc接口规范1.6》原文:
“命令请求和响应的内容都放在Http请求Entity Body中,并采用XML格式,内容类型(Content-Type)为:” text/plain”,在HTTP的包头里面的表示为:“Content-Type: text/plain”,请注意,在包头里,相关的限制和约定以HTTP及XML协议为准。”请问怎么得到EntityBody中的xml串?
“命令请求和响应的内容都放在Http请求Entity Body中,并采用XML格式,内容类型(Content-Type)为:” text/plain”,在HTTP的包头里面的表示为:“Content-Type: text/plain”,请注意,在包头里,相关的限制和约定以HTTP及XML协议为准。”请问怎么得到EntityBody中的xml串?
PrintWriter out = response.getWriter();
com.funcreal.misc.Provision p = new HebMy120Provision(request.getInputStream());
ServletContext app = request.getSession().getServletContext();
app.log("-----------------订购请求----------------------");
app.log("feeUserMsisdn:"+p.getFeeUser().getMsisdn());
app.log("pseudoCode:"+p.getFeeUser().getPseudoCode());
app.log("actionID:" + p.getActionID());
app.log("----------------------------------------------");
out.print(p.getResponse());
out.flush();
out.close();
写一个servlet解析就可以,在dopost里:
ServletInputStream in; DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(in);
//TransactionID
if(document.getElementsByTagName("TransactionID") != null
&& document.getElementsByTagName("TransactionID").item(0) != null
&& document.getElementsByTagName("TransactionID").item(0).getFirstChild() != null){
...
往下解析就行了
in = request.getInputStream();
Document doc = parse(request.getInputStream());
Element root = doc.getRootElement();
command_name = root.elementText("command_name");
Element Data_block = root.element("command_data_block");
Iterator it = Data_block.elementIterator();
while(it.hasNext()){
Element a = (Element)it.next();
if (a.getName().equals("action_id")) {
action_id = Integer.parseInt((String)a.getData());
} else if (a.getName().equals("service_id")){
service_id = (String)a.getData();
} else if (a.getName().equals("mid")){
mid = (String)a.getData();
} else if (a.getName().equals("mobile_id")){
mobile_id = (String)a.getData();
} else if (a.getName().equals("access_model")){
access_model += (String)a.getData() + "," ;
}
}
} catch(Exception e){
}