zoukankan      html  css  js  c++  java
  • 慎用Request.Params获取参数值

    今天一通道技术反映我们提交过去的url太长了,形如:

    引用内容
    http://service.5k3g.com/r.aspx?i=8986272,/ay/bajie10669611.ashx


    在日志中找了相应的记录,日志如下:

    引用内容
    http://219.140.177.243/ay/bajie10669611.ashx?pid=5&phone=13182000000&name=%e5%a8%83%e5%a8%83&url=http%3a%2f%2fservice.5k3g.com%2fr.aspx%3fi%3d8986272


    并没有多提交内容,最后发现原因是对方使用HttpContext.Current.Request.Params获取参数值。我们先来看一个例子:

    Response.Write(HttpContext.Current.Request.Params["url"]);
    Response.Write(HttpContext.Current.Request["url"]);


    1).http://localhost:1043/net/Send.aspx不带参数时结果:

    /net/Send.aspx //说明:Request.ServerVariables["url"]
    /net/Send.aspx //说明:Request.ServerVariables["url"]

    2).http://localhost:1043/net/Send.aspx?url=http://www.mzwu.com/带参数时结果:

    http://www.mzwu.com/,/net/Send.aspx //说明:Request.QueryString["url"],Request.ServerVariables["url"]
    http://www.mzwu.com/ //说明:Request.QueryString["url"]

    现在非常清楚了,我们来查看下官方两个方法的说明吧:

    HttpContext.Current.Request.Params是获取 System.Web.HttpRequest.QueryString、System.Web.HttpRequest.Form、System.Web.HttpRequest.ServerVariables 和 System.Web.HttpRequest.Cookies 项的组合集合;
    HttpContext.Current.Request是从System.Web.HttpRequest.Cookies、System.Web.HttpRequest.QueryString、System.Web.HttpRequest.Form 和 System.Web.HttpRequest.ServerVariables 集合中获取指定的对象。

    所以上边的问题只需将HttpContext.Current.Request.Params改为HttpContext.Current.Request即可。

  • 相关阅读:
    Hibernate 总结
    Mybatis 总结
    Mybatis原生DataSource源码解析
    Spring Cloud 服务安全
    Mybatis原生源码解析
    最好的Http客户端--Feign 源码分析
    Zuul整合Hystrix断路器
    Zuul核心-预定义Filter
    Feign性能优化
    Feign整合Ribbon负载均衡
  • 原文地址:https://www.cnblogs.com/yanglang/p/13073231.html
Copyright © 2011-2022 走看看