HttpWebRequest.Referer 設定或擷取來自搜尋引擎的網址

來源:互聯網
上載者:User

// Create a 'HttpWebRequest' object.

                          HttpWebRequest   myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);

                          // Set referer property  to http://www.microsoft.com .

                          myHttpWebRequest.Referer="http://www.microsoft.com";

                          // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.

                          HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();

                          // Display the contents of the page to the console.

                          Stream streamResponse=myHttpWebResponse.GetResponseStream();

                          StreamReader streamRead = new StreamReader( streamResponse );

                          Char[] readBuffer = new Char[256];

                          int count = streamRead.Read( readBuffer, 0, 256 );

                          Console.WriteLine("\nThe contents of HTML page are.......");

                          while (count > 0)

                          {

                                   String outputData = new String(readBuffer, 0, count);

                                   Console.Write(outputData);

                                   count = streamRead.Read(readBuffer, 0, 256);

                          }

                          Console.WriteLine("\nHTTP Request  Headers :\n\n{0}",myHttpWebRequest.Headers);

                          Console.WriteLine("\nHTTP Response Headers :\n\n{0}",myHttpWebResponse.Headers);

                          streamRead.Close();

                          streamResponse.Close();

                          // Release the response object resources.

                          myHttpWebResponse.Close();

                          Console.WriteLine("Referer to the site is:{0}",myHttpWebRequest.Referer);     

 

如果 AllowAutoRedirect 屬性為 true,則 Referer 屬性在請求被重新導向到另一個網站時自動化佈建。

 以上是設定,那麼怎麼擷取呢?

string lasturi= Request.ServerVariables["HTTP_REFERER"];

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.