如何获取http体 不带参数载体的-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

如何获取http体 不带参数载体的

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");等类似与这种形式

展开
收起
蛮大人123 2016-03-20 17:44:20 1933 0
1 条回答
写回答
取消 提交回答
  • 蛮大人123
    我说我不帅他们就打我,还说我虚伪
    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;
    }
    2019-07-17 19:09:53
    赞同 展开评论 打赏
问答排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载