接受第三方的post过来的xml,如果没有设置Content-Type: application/x-www-form-urlencoded。则可以通过流来解析
代码如下
BufferedReader in= new BufferedReader(new InputStreamReader(httpServletRequest.getInputStream()));
String s="";
StringBuffer sb=new StringBuffer();
while((s=in.readLine())!=null){
sb.append(s);
}
// dom解析xml
DocumentBuilderFactory buildFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder build = buildFactory.newDocumentBuilder();
Document document = build.parse(httpServletRequest.getInputStream(),"utf-8");
NodeList nodelist = document.getElementsByTagName("MO");
for (int i = 0; i < nodelist.getLength(); i++) {
longcodeArray.add(document.getElementsByTagName("LongCode").item(i).getFirstChild().getNodeValue().substring(1));
messageArray.add(document.getElementsByTagName("Message").item(i).getFirstChild().getNodeValue());
}
如果设置了Content-Type: application/x-www-form-urlencoded 则需要去parmmeterMap中间去取
List<String> longcodeArray=new ArrayList<String>();
List<String> messageArray=new ArrayList<String>();
try {
CreateLog log = new CreateLog();
HttpServletRequest httpServletRequest = this.getHttpServletRequest();
String keyandValue="";
String key="";
String value="";
Iterator<String> it=httpServletRequest.getParameterMap().keySet().iterator();
while(it.hasNext()){
key=it.next();
value = ((Object[])(httpServletRequest.getParameterMap().get(key)))[0].toString();
keyandValue=key+"="+value;
System.out.println(key+"= "+value);
}
if(keyandValue!=null){
//dom4j来解析xml字符串
Document document=DocumentHelper.parseText(keyandValue.toString());
Element root=document.getRootElement();
List mo=root.elements("MO");
for(int i=0;i<mo.size();i++){
Element longcode=((Element)mo.get(i)).element("LongCode");
Element message=((Element)mo.get(i)).element("Message");
longcodeArray.add(longcode.getText());
messageArray.add(message.getText());
}
}
分享到:
相关推荐
Content-Type: application/x-www-form-urlencoded Content-Length: length ll_a=string&ll_b=string*/ /*获取结果 HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length ...
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型。...form的enctype属性为编码方式,常用有两种: application/x-www-form-urlencoded 和 mult
1. 引言 1.1编写目的 本文是... 请求头Content-Type:application/x-www-form-urlencoded; 2.2 接口地址 测试地址:http://url:port/gateway.do 正式地址:http://url:port/gateway.do
Content-Type: application/x-www-form-urlencoded Content-Length: 200 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) Host: bbs....
Content-Type: application/x-www-form-urlencoded Content-Length: 62 Cookie: PHPSESSID=bf7u0ad95cbubpcvdjda2bqro3; Loggedin=True; EliteNinja=False module=Home&action=UnifiedSearch&search_form=false&...
Content-Type: application/x-www-form-urlencoded UA-CPU: x86 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) Host: entry.yeah.net Content-Length: 738 ...
iMyHttp.RequestJsonInfo((LPCTSTR)m_strUrl,Hr_Post,"Content-Type:application/x-www-form-urlencoded",strData,m_nTimeOut); if (!MyHttp.ParseJsonInfo()) { return OutPutFailInfo(MyHttp.GetErrInfo()); ...
Windows 98) Content-Length: 33 Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate LastName=Franks&FirstName=Michael 6 网络应用安全技术详解全文共57页,当前为第6页。...
headers:{"Content-Type":'application/x-www-form-urlencoded;charset=UTF-8'} 另外transformRequest函数 transformRequest: [function (data) { // 对 data 进行任意转换处理 let ret = '';
授权码认证 curl --location --request GET ' ...--header ' Content-Type: application/x-www-form-urlencoded ' \ --data-urlencode '
具有JWT身份验证的API服务器 ... --header 'content-type: application/x-www-form-urlencoded' \ --data username=travishorn \ --data password=password 注意只有一个用户, travishorn ,在datab
#Login Dropwizard Service 这是一个示例放置向导,用作教授有关集成和单元测试的新起点的基础##构建并运行...service-1.jar server##使用经过身份验证的用户请求 › curl -X POST -i -H "Content-Type: application/x-...
内容类型:application / x-www-form-urlencoded webbench-发布内容--header header1:value1 --header header2:value2 -t time -c数字 2.Content-Type:multipart / form-data; boundary = random_bytes_or_...
curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -H "Authorization: Basic dGVzdDpzZWNyZXQ=" -d "grant_type=password&username=johndoe&password=A3ddj3w" localhost:3000/oauth/token ...
需求必须具有标题: Content-Type: application/x-www-form-urlencoded 。 每个请求的主体必须具有一个名为“查询”的项目,其值必须是具有以下结构的“ json”: op:操作,内容是可以为"+" , "-" , "*"和"/"的...
要学习content-type,必须事先知道它到底是什么,是干什么用的。
application/x-www-form-urlencoded;charset=UTF-8for plain text. 内容如下: { "data": { "score": "5x1", "time": "15:10" }, "registration_ids": ["YourDeviceKeyId"] } 可以进行测试稍后我还有一篇博客...
提供,它解析middlware处理程序Content-Type: application/x-www-form-urlencoded机构插入的对象req.body 。 安装 npm install sw-body-url 例子 var http = require ( 'http' ) ; var sw = require ( '...
说明:只能接收Content-Type: application/x-www-form-urlencoded提交的数据 解释:也就是表单POST过来的数据 方法2、file_get_contents(“php://input”); 说明: 允许读取 POST 的原始数据。 和 $...
multipart/form-data主要是为了解决application/x-www-form-urlencoded编码格式在传输大量二进制数据或包含非ASCII字符文本时的低效问题。multipart/form-data的数据由多个part组成,part间通过boundary分隔符进行...