Introduced
We all know that micro-credit payment callback link requirements cannot be with parameters, but also receive the returned XML data. I started using @RequestBody annotations on parameters, hoping to get XML data, and the test failed. The last use HttpServletRequest to get the data was successful.
Sample code
@RequestMapping ("/weixinpay/callback") public
String callback (HttpServletRequest request) {
InputStream is = Request.getinputstream ();
String XML = streamutil.inputstream2string (IS, "UTF-8")
/**
* Convert XML to map based on data for logical processing/
}
/**
* InputStream flow replaced by string string
* @param instream inputstream Stream
* @param encoding encoding format
* @return string literal
*
/public static string inputstream2string (InputStream instream, string encoding) {
string result = NULL;
try {
if (instream!= null) {
Bytearrayoutputstream outstream = new Bytearrayoutputstream ();
byte[] tempbytes = new Byte[_buffer_size];
int count =-1;
while ((count = Instream.read (tempbytes, 0, _buffer_size))!=-1) {
outstream.write (tempbytes, 0, Count);
}
Tempbytes = null;
Outstream.flush ();
result = new String (Outstream.tobytearray (), encoding);
}
catch (Exception e) {result
= null;
}
return result;
}
Summarize
The above is the entire content of this article, I hope to be able to learn or work to bring certain help, if you have questions you can message exchange.