标签:body readline utf-8 puts output ringbuf alt catch message
InputStream inputStream = null ;
try {
inputStream = request.getInputStream();
BufferedInputStream byteOutputStream = new BufferedInputStream( inputStream );
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int a ;
while( ( a = byteOutputStream.read( bytes ) ) != -1){
byteArrayOutputStream.write( bytes , 0 , a);
}
String s = byteArrayOutputStream.toString("utf-8");
return s;
}catch(IOException e){
e.printStackTrace();
return e.getMessage();
}finally{
if(inputStream != null ){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2 . 字符流
BufferedReader reader = null ;
try {
reader = request.getReader();
StringBuffer sb = new StringBuffer();
String str ;
while (null != (str = reader.readLine())){
sb.append( str );
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
return e.getMessage();
}finally {
if(null == reader){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3 . RequestBody方式 直接Map 或者 对象来接收 ,这个需要知道对方传输过来的样式
这样Map就可以直接拿到了 .
标签:body readline utf-8 puts output ringbuf alt catch message
原文地址:https://www.cnblogs.com/liweibing/p/13087351.html