1. <small id='ULmiV'></small><noframes id='ULmiV'>

      <legend id='ULmiV'><style id='ULmiV'><dir id='ULmiV'><q id='ULmiV'></q></dir></style></legend>

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

        在 c# 中请求网页欺骗主机

        时间:2023-10-25
        <i id='Nrcn4'><tr id='Nrcn4'><dt id='Nrcn4'><q id='Nrcn4'><span id='Nrcn4'><b id='Nrcn4'><form id='Nrcn4'><ins id='Nrcn4'></ins><ul id='Nrcn4'></ul><sub id='Nrcn4'></sub></form><legend id='Nrcn4'></legend><bdo id='Nrcn4'><pre id='Nrcn4'><center id='Nrcn4'></center></pre></bdo></b><th id='Nrcn4'></th></span></q></dt></tr></i><div id='Nrcn4'><tfoot id='Nrcn4'></tfoot><dl id='Nrcn4'><fieldset id='Nrcn4'></fieldset></dl></div>
        • <legend id='Nrcn4'><style id='Nrcn4'><dir id='Nrcn4'><q id='Nrcn4'></q></dir></style></legend>

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

                <tbody id='Nrcn4'></tbody>

            • <tfoot id='Nrcn4'></tfoot>
                <bdo id='Nrcn4'></bdo><ul id='Nrcn4'></ul>
                1. 本文介绍了在 c# 中请求网页欺骗主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要为发送到我们网站的网页创建一个请求,但我还需要能够设置主机标头信息.我已经尝试过使用 HttpWebRequest,但是标头信息是只读的(或者至少它的主机部分是只读的).我需要这样做,因为我们想在用户之前执行页面的初始请求.我们有 10 个负载均衡的 Web 服务器,因此我们需要从每个 Web 服务器请求文件.

                  I need to create a request for a web page delivered to our web sites, but I need to be able to set the host header information too. I have tried this using HttpWebRequest, but the Header information is read only (Or at least the Host part of it is). I need to do this because we want to perform the initial request for a page before the user can. We have 10 web server which are load balanced, so we need to request the file from each of the web servers.

                  我尝试了以下方法:

                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.1.5/filename.htm");
                  request.Headers.Set("Host", "www.mywebsite.com");
                  WebResponse response = request.GetResponse();
                  

                  显然这不起作用,因为我无法更新标题,而且我不知道这是否确实是正确的方法.

                  Obviously this does not work, as I can't update the header, and I don't know if this is indeed the right way to do it.

                  推荐答案

                  我已经设法通过使用套接字找到了一条更漫长的路线.我在 IPEndPoint 的 MSDN 页面中找到了答案:

                  I have managed to find out a more long winded route by using sockets. I found the answer in the MSDN page for IPEndPoint:

                  string getString = "GET /path/mypage.htm HTTP/1.1
                  Host: www.mysite.mobi
                  Connection: Close
                  
                  ";
                  Encoding ASCII = Encoding.ASCII;
                  Byte[] byteGetString = ASCII.GetBytes(getString);
                  Byte[] receiveByte = new Byte[256];
                  Socket socket = null;
                  String strPage = null;
                  try
                  {
                      IPEndPoint ip = new IPEndPoint(IPAddress.Parse("10.23.1.93"), 80);
                      socket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                      socket.Connect(ip);
                  }
                  catch (SocketException ex)
                  {
                      Console.WriteLine("Source:" + ex.Source);
                      Console.WriteLine("Message:" + ex.Message);
                  }
                  socket.Send(byteGetString, byteGetString.Length, 0);
                  Int32 bytes = socket.Receive(receiveByte, receiveByte.Length, 0);
                  strPage = strPage + ASCII.GetString(receiveByte, 0, bytes);
                  
                  while (bytes > 0)
                  {
                      bytes = socket.Receive(receiveByte, receiveByte.Length, 0);
                      strPage = strPage + ASCII.GetString(receiveByte, 0, bytes);
                  }
                  socket.Close();
                  

                  这篇关于在 c# 中请求网页欺骗主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何向 WCF 服务添加跨域支持 下一篇:IsPostback 在技术上是如何工作的?

                  相关文章

                2. <legend id='PX1Vc'><style id='PX1Vc'><dir id='PX1Vc'><q id='PX1Vc'></q></dir></style></legend>

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

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

                      <tfoot id='PX1Vc'></tfoot>
                    1. <small id='PX1Vc'></small><noframes id='PX1Vc'>