• <legend id='asBeg'><style id='asBeg'><dir id='asBeg'><q id='asBeg'></q></dir></style></legend>

    <tfoot id='asBeg'></tfoot>

      <bdo id='asBeg'></bdo><ul id='asBeg'></ul>

    <i id='asBeg'><tr id='asBeg'><dt id='asBeg'><q id='asBeg'><span id='asBeg'><b id='asBeg'><form id='asBeg'><ins id='asBeg'></ins><ul id='asBeg'></ul><sub id='asBeg'></sub></form><legend id='asBeg'></legend><bdo id='asBeg'><pre id='asBeg'><center id='asBeg'></center></pre></bdo></b><th id='asBeg'></th></span></q></dt></tr></i><div id='asBeg'><tfoot id='asBeg'></tfoot><dl id='asBeg'><fieldset id='asBeg'></fieldset></dl></div>

    <small id='asBeg'></small><noframes id='asBeg'>

        在 ASP.net C# 中伪造浏览器请求

        时间:2023-10-25
            <bdo id='VJfIA'></bdo><ul id='VJfIA'></ul>

              <tbody id='VJfIA'></tbody>
            • <tfoot id='VJfIA'></tfoot>

                  <small id='VJfIA'></small><noframes id='VJfIA'>

                  <i id='VJfIA'><tr id='VJfIA'><dt id='VJfIA'><q id='VJfIA'><span id='VJfIA'><b id='VJfIA'><form id='VJfIA'><ins id='VJfIA'></ins><ul id='VJfIA'></ul><sub id='VJfIA'></sub></form><legend id='VJfIA'></legend><bdo id='VJfIA'><pre id='VJfIA'><center id='VJfIA'></center></pre></bdo></b><th id='VJfIA'></th></span></q></dt></tr></i><div id='VJfIA'><tfoot id='VJfIA'></tfoot><dl id='VJfIA'><fieldset id='VJfIA'></fieldset></dl></div>
                1. <legend id='VJfIA'><style id='VJfIA'><dir id='VJfIA'><q id='VJfIA'></q></dir></style></legend>
                  本文介绍了在 ASP.net C# 中伪造浏览器请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用下面的代码来提取我们的第 3 方开发页面之一,以便我可以将其解析为 XML 以用于我的随机工作.

                  I'm using the code below to pull one of our 3rd party developed pages in so I can parse it as XML for my random bits of work.

                  令人恼火的是,我们仍然在服务器上设置了浏览器检测级别,只允许某些浏览器访问该站点;所以问题是我如何伪造它以便服务器认为它是浏览器请求?

                  Irritatingly we stil have a browser detection level set on the server that only allows certain browsers on to the site; so the question is how would I fake it so that the server thinks its a browser request?

                     static string GetHtmlPage(string strURL)
                      {
                  
                          String strResult;
                          System.Net.WebResponse objResponse;
                  
                          System.Net.WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
                  
                          objResponse = objRequest.GetResponse();
                          using (System.IO.StreamReader sr = new System.IO.StreamReader(objResponse.GetResponseStream()))
                          {
                              strResult = sr.ReadToEnd();
                              sr.Close();
                          }
                          return strResult;
                      }
                  

                  推荐答案

                  浏览器检测是基于对服务器的请求中的标头完成的.您需要做的就是设置该标题.但是,使用 HttpWebRequest 您不是通过 headers 集合设置它,而是使用 .UserAgent 属性.

                  Browser detection is done based on a header in the request to the server. All you need to do is set that header. However, with HttpWebRequest you don't set that through the headers collection but rather with the .UserAgent property.

                  ...
                  System.Net.WebRequest objRequest = 
                     System.Net.HttpWebRequest.Create(strURL);
                  
                  //Pretend to be IE7
                  ((System.Net.HttpWebRequest)objRequest).UserAgent = 
                     "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)";
                  
                  objResponse = objRequest.GetResponse();
                  ...
                  

                  这篇关于在 ASP.net C# 中伪造浏览器请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从响应中删除 IIS 自定义标头,例如 X-Powered-By: ASP.NET? 下一篇:使用 HttpWebRequest 添加自定义标头

                  相关文章

                    <bdo id='c6G9C'></bdo><ul id='c6G9C'></ul>

                      <legend id='c6G9C'><style id='c6G9C'><dir id='c6G9C'><q id='c6G9C'></q></dir></style></legend>
                    1. <i id='c6G9C'><tr id='c6G9C'><dt id='c6G9C'><q id='c6G9C'><span id='c6G9C'><b id='c6G9C'><form id='c6G9C'><ins id='c6G9C'></ins><ul id='c6G9C'></ul><sub id='c6G9C'></sub></form><legend id='c6G9C'></legend><bdo id='c6G9C'><pre id='c6G9C'><center id='c6G9C'></center></pre></bdo></b><th id='c6G9C'></th></span></q></dt></tr></i><div id='c6G9C'><tfoot id='c6G9C'></tfoot><dl id='c6G9C'><fieldset id='c6G9C'></fieldset></dl></div>

                      <small id='c6G9C'></small><noframes id='c6G9C'>

                      <tfoot id='c6G9C'></tfoot>