zoukankan      html  css  js  c++  java
  • 跟据HttpRequest获取body内数据

    1 . 字节流

    
    
    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就可以直接拿到了 . 


    人总得做点什么 ,不是么
  • 相关阅读:
    BOM与DOM
    前端基础之JavaScript
    前端基础之css
    前端基础之HTML
    索引与慢查询优化
    视图、触发器、事务、存储过程、函数、流程控制
    pymysql模块
    mysql的基本查询语句及方法
    ie6 select选中问题
    offsetLeft
  • 原文地址:https://www.cnblogs.com/liweibing/p/13087351.html
Copyright © 2011-2022 走看看