java web中获取请求体中的内容
来源:互联网 发布:caffe rfcn 编辑:程序博客网 时间:2024/06/06 01:33
原文地址http://hw1287789687.iteye.com/blog/1988694
/***
* Compatible with GET and POST*
* @param request
* @return : <code>byte[]</code>
* @throws IOException
*/
public static byte[] getRequestQuery(HttpServletRequest request)
throws IOException {
String submitMehtod = request.getMethod();
String queryString = null;
if (submitMehtod.equals("GET")) {// GET
queryString = request.getQueryString();
String charEncoding = request.getCharacterEncoding();// charset
if (charEncoding == null) {
charEncoding = "UTF-8";
}
return queryString.getBytes(charEncoding);
} else {// POST
return getRequestPostBytes(request);
}
}
/***
* Get request query string, form method : post
*
* @param request
* @return byte[]
* @throws IOException
*/
public static byte[] getRequestPostBytes(HttpServletRequest request)
throws IOException {
int contentLength = request.getContentLength();
if(contentLength<0){
return null;
}
byte buffer[] = new byte[contentLength];
for (int i = 0; i < contentLength;) {
int readlen = request.getInputStream().read(buffer, i,
contentLength - i);
if (readlen == -1) {
break;
}
i += readlen;
}
return buffer;
}
/***
* Get request query string, form method : post
*
* @param request
* @return
* @throws IOException
*/
public static String getRequestPostStr(HttpServletRequest request)
throws IOException {
byte buffer[] = getRequestPostBytes(request);
String charEncoding = request.getCharacterEncoding();
if (charEncoding == null) {
charEncoding = "UTF-8";
}
return new String(buffer, charEncoding);
}
0 0
- java web中获取请求体中的内容
- java获取请求url中的内容
- java通过HttpServletRequest获取post请求中的body内容
- java web中的内容
- Java 获取http请求头内容
- Java Web 中通过request请求头获取客户端真实IP
- .net webapi控制器函数中与MVC控制器函数中,获取到请求中的文本内容和文件流内容的写法
- JS 获取页面中iframe中的内容
- 在WebView中获取网页中的内容
- java获取excle中的内容测试源码
- 从请求中获取xml内容并解析成map
- java web请求url获取json数据获取value值
- Java 与 PHP 发送get请求并获取远程内容
- Java web 中请求路径的问题
- java中获取字符串之间的内容
- http 请求获取页面内容
- Java Web -- Servlet(12)HttpServletRequest详解(获取请求数据、请求分派、请求域)(1)
- Java Web -- Servlet(13)HttpServletRequest详解(获取请求数据、请求分派、请求域)(2)
- restore hadoop primary namenode from secondary namenode checkpoint step by step
- 2014年阿里(实习)算法工程师面试
- 字符c是否为字母或数字
- HTML标签
- 文本域加滚动条
- java web中获取请求体中的内容
- Time 类中的运算符重载
- ThreadLocal——神一样的东东,我今天把它彻底解释清楚了
- 李国庆PK刘强东:最失败是品类战略
- mysql高级之权限-查看表
- SQL SERVER 2000用sql语句如何获得当前系统时间
- 论”三生万物“
- 《黑马程序员》 IO之文件拷贝
- myEclipse不能部署项目