WebHeaderCollection.GetValues Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém um array de valores de cabeçalho armazenados num cabeçalho.
Sobrecargas
| Name | Description |
|---|---|
| GetValues(String) |
Obtém um array de valores de cabeçalho armazenados num cabeçalho. |
| GetValues(Int32) |
Obtém um array de valores de cabeçalho armazenados na |
GetValues(String)
Obtém um array de valores de cabeçalho armazenados num cabeçalho.
public:
override cli::array <System::String ^> ^ GetValues(System::String ^ header);
public override string[] GetValues(string header);
override this.GetValues : string -> string[]
Public Overrides Function GetValues (header As String) As String()
Parâmetros
- header
- String
O cabeçalho para voltar.
Devoluções
Uma variedade de cordas de cabeçalho.
Exemplos
O exemplo seguinte utiliza o GetValues método para recuperar um array de valores para cada cabeçalho no WebHeaderCollection.
// Create a web request for "www.msn.com".
HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("http://www.msn.com");
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]);
}
else
{
Console.WriteLine("There is no value associated with the header");
}
}
myHttpWebResponse.Close();
'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
Else
Console.WriteLine("There is no value associated with the header")
End If
Next i
Observações
GetValues devolve o conteúdo do cabeçalho especificado como um array.
Aplica-se a
GetValues(Int32)
Obtém um array de valores de cabeçalho armazenados na index posição da coleção de cabeçalhos.
public:
override cli::array <System::String ^> ^ GetValues(int index);
public override string[] GetValues(int index);
override this.GetValues : int -> string[]
Public Overrides Function GetValues (index As Integer) As String()
Parâmetros
- index
- Int32
O índice do cabeçalho para regressar.
Devoluções
Uma variedade de cordas de cabeçalho.
Observações
GetValues devolve o conteúdo do cabeçalho especificado como um array.