zoukankan      html  css  js  c++  java
  • 工具类通用http工具封装

    package com.jyc.common.utils.http;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.nio.charset.Charset;
    import javax.servlet.ServletRequest;
    import org.apache.commons.lang3.exception.ExceptionUtils;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    /**
    * 通用http工具封装
    *
    * @author jianyongchao
    */
    public class HttpHelper
    {
    private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class);

    public static String getBodyString(ServletRequest request)
    {
    StringBuilder sb = new StringBuilder();
    BufferedReader reader = null;
    try (InputStream inputStream = request.getInputStream())
    {
    reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
    String line = "";
    while ((line = reader.readLine()) != null)
    {
    sb.append(line);
    }
    }
    catch (IOException e)
    {
    LOGGER.warn("getBodyString出现问题!");
    }
    finally
    {
    if (reader != null)
    {
    try
    {
    reader.close();
    }
    catch (IOException e)
    {
    LOGGER.error(ExceptionUtils.getMessage(e));
    }
    }
    }
    return sb.toString();
    }
    }
  • 相关阅读:
    去除inline-block出现间距的几种方法
    vscode插件和快捷键
    es6三个点运算符
    jq返回顶部
    jq版轮播图
    js动态操作DOM
    js中的闭包
    es6之箭头函数
    in和hasOwnProperty的区别
    改变this指向的三种方法
  • 原文地址:https://www.cnblogs.com/qq3245792286/p/15469761.html
Copyright © 2011-2022 走看看