Export (0) Print
Expand All

WebHeaderCollection.GetValues Method (String)

Gets an array of header values stored in a header.

Namespace:  System.Net
Assembly:  System (in System.dll)

Public Overrides Function GetValues ( _
	header As String _
) As String()


Type: System.String

The header to return.

Return Value

Type: System.String()
An array of header strings.

GetValues returns the contents of the specified header as an array.

The following example uses the GetValues method to retrieve an array of values for each header in the WebHeaderCollection.

            'Create a web request for "www.msn.com". 
            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
	    myHttpWebRequest.Timeout = 1000
            'Get the associated response for the above request. 
            Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

            'Get the headers associated with the response. 
            Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebResponse.Headers
            Dim i As Integer 
            For i = 0 To myWebHeaderCollection.Count - 1
                Dim header As [String] = myWebHeaderCollection.GetKey(i)
                Dim values As [String]() = myWebHeaderCollection.GetValues(header)
                If values.Length > 0 Then
                    Console.WriteLine("The values of {0} header are : ", header)
                    Dim j As Integer 
                    For j = 0 To values.Length - 1
                        Console.WriteLine(ControlChars.Tab + "{0}", values(j))
                    Next j
                    Console.WriteLine("There is no value associated with the header")
                End If 
            Next i 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft