This documentation is archived and is not being maintained.

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()
Dim instance As WebHeaderCollection
Dim header As String
Dim returnValue As String()

returnValue = instance.GetValues(header)
public String[] GetValues (
	String header
public override function GetValues (
	header : String
) : String[]
Not applicable.



The header to return.

Return Value

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 "".
    Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(""), 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 

// Create a web request for "".
HttpWebRequest myHttpWebRequest = (HttpWebRequest)(
// Get the associated response for the above request.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)(
// Get the headers associated with the response.
WebHeaderCollection myWebHeaderCollection = myHttpWebResponse.

for (int i = 0; i < myWebHeaderCollection.get_Count(); i++) {
    String header = myWebHeaderCollection.GetKey(i);
    String values[] = myWebHeaderCollection.GetValues(header);
    if (values.get_Length() > 0) {
        Console.WriteLine("The values of {0} header are : ", header);
        for (int j = 0; j < values.get_Length(); j++) {
            Console.WriteLine("\t{0}", values.get_Item(j));
    else {
        Console.WriteLine("There is no value associated with the" 
            + " header");

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0