parent
ab992f4848
commit
02062f31e9
@ -0,0 +1,56 @@ |
||||
package com.ruoyi.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.lang.exception.ExceptionUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* 通用http工具封装 |
||||
* |
||||
* @author ruoyi |
||||
*/ |
||||
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.getFullStackTrace(e)); |
||||
} |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
} |
Loading…
Reference in new issue