GetValues Method (String)
Collapse the table of content
Expand the table of content

WebHeaderCollection.GetValues Method (String)

Gets an array of header values stored in a header.

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

public override string[] GetValues(
	string header


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 "".
 HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("");
myHttpWebRequest.Timeout = 1000;
// Get the associated response for the above request.
 HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();

// Get the headers associated with the response.
WebHeaderCollection myWebHeaderCollection = myHttpWebResponse.Headers;

for(int i = 0; i < myWebHeaderCollection.Count; i++) {
    String header = myWebHeaderCollection.GetKey(i);
    String[] values = myWebHeaderCollection.GetValues(header);
    if(values.Length > 0) {
        Console.WriteLine("The values of {0} header are : ", header);
        for(int j = 0; j < values.Length; j++) 
            Console.WriteLine("\t{0}", values[j]);
        Console.WriteLine("There is no value associated with the header");
// Create a web request for S"".
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*> (WebRequest::Create(S""));
myHttpWebRequest->Timeout = 1000;
// Get the associated response for the above request.
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*> (myHttpWebRequest->GetResponse());

// Get the headers associated with the response.
WebHeaderCollection* myWebHeaderCollection = myHttpWebResponse->Headers;

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

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

© 2015 Microsoft