最近有在搞中国移动支付SDK接入,那服务端的demo实在看不明白,为何接收一个通知会搞到配置文件,还sping,加群又没有人理,或许是自己水平太差看不明白要怎么搞,最终折腾的这样处理了
1、接收过来得到字符XML,不过得到的生成的字符却不能用dom4解析,提示说头部多个问号,就不是标准xml,可能是下面方法有点问题,后来通过截取头到尾指定字符再接成标准的xml能解析了
public static String readServletInputStream(HttpServletRequest req)
{
String content = null;
ServletInputStream sis =null;
ByteArrayOutputStream baos = null;
try
{
sis=req.getInputStream();
byte[] b = new byte[1024];
int count = -1;
baos = new ByteArrayOutputStream();
while ((count = sis.read(b)) != -1)
{
baos.write(b, 0, count);
}
baos.flush();
content = baos.toString("UTF-8");
baos.close();
sis.close();
} catch (IOException e)
{
e.printStackTrace();
}
finally
{
baos=null;
sis=null;
}
return content;
}