POST /api/cloud2 HTTP/1.1
Accept-Encoding: identity
Content-Length: 379
Host: 59.108.68.130:8622
Content-Type: application/x-www-form-urlencoded
Connection: close
User_Agent: glibc
{"ver":"3.5","uid":"ffffffffffffffffffffffffffffffff","ip":"192.168.85.185","pid":"uploadfile/3.5","data":{"type":"file","data":[{"crc":"","infotype":"fileinfov1","dtype":"1","alen":325,"path":"","md5":"5a7fcae69b3fa13f8517ede1353d6f9a","extype":"5-tuple","ex":{"src ip":"1.1.1.1","src port":1714,"dst ip":"2.2.2.2","dst port":21,"proto":"ftp"}}]},"key":"test","type":"fileinfo"}HTTP/1.1
这种请求 在struts2中如何获取,主体内容没有参数体不能 request.getParameter("sss");等类似与这种形式
public static String getPacket(HttpServletRequest request, String logFlag) {
String packet = request.getParameter(Constants.PACKET);
if (packet == null) {
try {
InputStream is = request.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
List byteList = new ArrayList();
byte[] temp = new byte[1];
while (bis.read(temp) != -1) {
byteList.add(temp[0]);
}
int size = byteList.size();
if (size > 0) {
byte[] b = new byte[size];
for (int i = 0; i < size; i++) {
b[i] = byteList.get(i);
}
packet = new String(b, Constants.ENCODE);
} else {
LOGGER.info("[" + logFlag + "] 从request中获取请求数据流中获取为空 ");
}
} catch (Exception e) {
LOGGER.error("[" + logFlag + "] 从request中获取请求数据流异常: " + e.toString(), e);
}
}
LOGGER.info(orgLog(logFlag, "获取请求报文", "uri[#0]packet[#1]", request.getRequestURI(), packet));
return packet;
}
{"ver":"3.5","uid":"ffffffffffffffffffffffffffffffff","ip":"192.168.85.185","pid":"uploadfile/3.5","data":{"type":"file","data":[{"crc":"","infotype":"fileinfov1","dtype":"1","alen":325,"path":"","md5":"5a7fcae69b3fa13f8517ede1353d6f9a","extype":"5-tuple","ex":{"src ip":"1.1.1.1","src port":1714,"dst ip":"2.2.2.2","dst port":21,"proto":"ftp"}}]},"key":"test","type":"fileinfo"}这一大串不都是?