ヘッダーに格納されたヘッダー値の配列を取得します。
Overrides Overloads Public Function GetValues( _
ByVal header As String _) As String()
[C#]
public override string[] GetValues(stringheader);
[C++]
public: String* GetValues(String* header) __gc[];
[JScript]
public override function GetValues(
header : String) : String[];
パラメータ
- header
返されるヘッダー。
戻り値
ヘッダー文字列の配列。
解説
GetValues は、指定したヘッダーの内容を配列として返します。
使用例
[Visual Basic, C#, C++] GetValues メソッドを使用して、 WebHeaderCollection の各ヘッダーの値の配列を取得する例を次に示します。
'Create a web request for "www.msn.com".
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("https://www.msn.com"), HttpWebRequest)
'********* the line 23 is causing problem . it is not necessary and can be deleted.
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
'The Snippet for 'GetValues(string)' method of 'WebHeaderCollection' class starts here---->
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
[C#]
// Create a web request for "www.msn.com".
HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("https://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();
[C++]
// Create a web request for S"www.msn.com".
HttpWebRequest* myHttpWebRequest =
dynamic_cast<HttpWebRequest*> (WebRequest::Create(S"https://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);
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");
}
myHttpWebResponse->Close();
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
WebHeaderCollection クラス | WebHeaderCollection メンバ | System.Net 名前空間 | WebHeaderCollection.GetValues オーバーロードの一覧