• 【java】之获取HTTP请求的值常用方法


     

     

    logger.info("销帐完成通知回调,请求URL:"+req.getRequestURI().toString());
    
    InputStream in = req.getInputStream();
    byte[] b=new byte[1024];
    ByteArrayOutputStream  out=new ByteArrayOutputStream();
    int len=-1;
    while((len=in.read(b))!=-1){
        out.write(b,0,len);
    }
    out.close();
    in.close();
    String strVal= new String(out.toByteArray(),"UTF-8");
    
    logger.info("销帐完成通知回调,请求参数-流形式:"+strVal);
    Map parameterMap = req.getParameterMap();
    Iterator entries = parameterMap.entrySet().iterator();
    String name = "";
    String value = "";
    String  strFormValue="";
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        name = (String) entry.getKey();
        Object valueObj = entry.getValue();
        if(null == valueObj){
            value = "";
        }else if(valueObj instanceof String[]){
            String[] values = (String[])valueObj;
            for(int i=0;i<values.length;i++){
                value = values[i] + ",";
            }
            value = value.substring(0, value.length()-1);
        }else{
            value = valueObj.toString();
        }
        strFormValue+=name+"----"+value+"-";
    }
    logger.info("销帐完成通知回调,请求参数-form形式:"+strFormValue);
    logger.info("销帐完成通知回调,请求参数-拼接形式:"+req.getQueryString());
    logger.info("销帐完成通知回调,时间为:"+DateTime.now().toString("yyyyMMdd HHmmss"));
    System.out.println("支付完成回调....");
    

      

  • 相关阅读:

    双向链表和环形链表(约瑟夫问题)
    单向链表的增删查改
    稀疏数组与环形数组
    离焦事件。这个坑谁抗的住呀,好无语呀
    maven
    maven工程运行出Unable to compile class for JSP: 错误
    笔记-JavaWeb学习之旅19
    获取redis cluster master对应的slot分布情况
    批量获取mysql数据库实例指定参数的值
  • 原文地址:https://www.cnblogs.com/gyjx2016/p/6525645.html
Copyright © 2020-2023  润新知