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


    人总得做点什么 ,不是么
  • 相关阅读:
    PC-CSS-默认字体样式
    PC--CSS维护
    PC--CSS技巧
    PC--CSS优化
    PC--CSS命名
    PC--CSS常识
    Base64与MIME和UTF-7
    Base64算法与多版本加密技术
    Base64算法与MD5加密原理
    log4j的使用
  • 原文地址:https://www.cnblogs.com/liweibing/p/13087351.html
Copyright © 2011-2022 走看看