风行天涯 2015-11-19 01:42 采纳率: 0%
浏览 1435
已结题

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

  • 写回答

2条回答 默认 最新

  • kutuzov2016 2015-11-19 09:03
    关注

    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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样