WebHeaderCollection.GetValues 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得儲存於標頭中的標頭值陣列。
多載
GetValues(String) |
取得儲存於標頭中的標頭值陣列。 |
GetValues(Int32) |
取得儲存於標頭集合的 |
GetValues(String)
取得儲存於標頭中的標頭值陣列。
public:
override cli::array <System::String ^> ^ GetValues(System::String ^ header);
public override string[]? GetValues (string header);
public override string[] GetValues (string header);
override this.GetValues : string -> string[]
Public Overrides Function GetValues (header As String) As String()
參數
- header
- String
要傳回的標頭。
傳回
String[]
標頭字串的陣列。
範例
下列範例會 GetValues 使用 方法來擷取 中 WebHeaderCollection每個標頭的值數組。
// Create a web request for S"www.msn.com".
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.msn.com" ));
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 );
array<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".
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
備註
GetValues 傳回指定標頭的內容做為陣列。
適用於
GetValues(Int32)
取得儲存於標頭集合的 index
位置之標頭值的陣列。
public:
override cli::array <System::String ^> ^ GetValues(int index);
public override string[]? GetValues (int index);
public override string[] GetValues (int index);
override this.GetValues : int -> string[]
Public Overrides Function GetValues (index As Integer) As String()
參數
- index
- Int32
要傳回的標頭索引。
傳回
String[]
標頭字串的陣列。
備註
GetValues 傳回指定標頭的內容做為陣列。