Aracılığıyla paylaş


HttpWebResponse.Headers Özellik

Tanım

Sunucudan bu yanıtla ilişkili üst bilgileri alır.

public:
 virtual property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); };
public override System.Net.WebHeaderCollection Headers { get; }
member this.Headers : System.Net.WebHeaderCollection
Public Overrides ReadOnly Property Headers As WebHeaderCollection

Özellik Değeri

WebHeaderCollection Yanıtla birlikte döndürülen üst bilgi bilgilerini içeren bir.

Özel durumlar

Geçerli örnek atıldı.

Örnekler

Aşağıdaki örnek, tüm yanıt üst bilgilerinin içeriğini konsola yazar.

// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( url ));

// Sends the HttpWebRequest and waits for response.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());

// Displays all the headers present in the response received from the URI.
Console::WriteLine( "\r\nThe following headers were received in the response:" );

// Displays each header and its key associated with the response.
for ( int i = 0; i < myHttpWebResponse->Headers->Count; ++i )
   Console::WriteLine( "\nHeader Name: {0}, Value : {1}",
      myHttpWebResponse->Headers->Keys[ i ],
      myHttpWebResponse->Headers[ (System::Net::HttpRequestHeader)i ] );

// Releases the resources of the response.
myHttpWebResponse->Close();
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

// Displays all the headers present in the response received from the URI.
Console.WriteLine("\r\nThe following headers were received in the response:");
// Displays each header and it's key associated with the response.
for(int i=0; i < myHttpWebResponse.Headers.Count; ++i)
    Console.WriteLine("\nHeader Name:{0}, Value :{1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]);
// Releases the resources of the response.
myHttpWebResponse.Close();
' Creates an HttpWebRequest with the specified URL. 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
' Sends the HttpWebRequest and waits for a response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Displays all the Headers present in the response received from the URI.
Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "The following headers were received in the response")
'The Headers property is a WebHeaderCollection. Use it's properties to traverse the collection and display each header.
Dim i As Integer
While i < myHttpWebResponse.Headers.Count
    Console.WriteLine(ControlChars.Cr + "Header Name:{0}, Value :{1}", myHttpWebResponse.Headers.Keys(i), myHttpWebResponse.Headers(i))
  i = i + 1
End While
myHttpWebResponse.Close()

Açıklamalar

Headers özelliği, yanıtla birlikte döndürülen HTTP üst bilgi değerlerini içeren bir ad/değer çiftleri koleksiyonudur. İnternet kaynağından döndürülen ortak üst bilgi bilgileri sınıfının özellikleri HttpWebResponse olarak kullanıma sunulur. Aşağıdaki tabloda API'nin özellik olarak kullanıma sunun ortak üst bilgileri listelemektedir.

Üst bilgi Özellik
İçerik Kodlama ContentEncoding
İçerik Uzunluğu ContentLength
İçerik Türü ContentType
Last-Modified LastModified
Sunucu Server

Şunlara uygulanır