WebHeaderCollection.Add 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
새 헤더를 컬렉션에 삽입합니다.
오버로드
| Add(String) |
지정된 헤더를 컬렉션에 삽입합니다. |
| Add(HttpRequestHeader, String) |
지정된 값을 가진 지정된 헤더를 컬렉션에 삽입합니다. |
| Add(HttpResponseHeader, String) |
지정된 값을 가진 지정된 헤더를 컬렉션에 삽입합니다. |
| Add(String, String) |
지정된 이름과 값을 갖고 있는 헤더를 컬렉션에 삽입합니다. |
Add(String)
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
지정된 헤더를 컬렉션에 삽입합니다.
public:
void Add(System::String ^ header);
public void Add (string header);
override this.Add : string -> unit
Public Sub Add (header As String)
매개 변수
- header
- String
이름과 값이 콜론으로 분리된 추가할 헤더입니다.
예외
header이 null 또는 Empty입니다.
header에 콜론(:)이 들어 있지 않은 경우
value의 길이가 65535를 넘는 경우
또는
header의 이름 부분이 Empty이거나 잘못된 문자를 포함하는 경우
또는
header가 속성을 사용하여 설정해야 하는 제한된 헤더인 경우
또는
header의 값 부분에 잘못된 문자가 들어 있는 경우
.NET Framework 및 .NET Core 버전 2.0 - 3.1만 해당: 콜론(:) 뒤에 오는 문자열의 길이가 65535자를 넘는 경우
예제
다음 예제에서는 메서드를 사용하여 Add 이름/값 쌍을 에 WebHeaderCollection 추가합니다.
try
{
//Create a web request for S"www.msn.com".
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.msn.com" ));
//Get the headers associated with the request.
WebHeaderCollection^ myWebHeaderCollection = myHttpWebRequest->Headers;
Console::WriteLine( "Configuring Webrequest to accept Danish and English language using 'Add' method" );
//Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection->Add( "Accept-Language:da" );
//Include English in the Accept-Langauge header.
myWebHeaderCollection->Add( "Accept-Language:en;q=0.8" );
//Get the associated response for the above request.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());
//Print the headers for the request.
printHeaders( myWebHeaderCollection );
myHttpWebResponse->Close();
}
//Catch exception if trying to add a restricted header.
catch ( ArgumentException^ e )
{
Console::WriteLine( e->Message );
}
catch ( WebException^ e )
{
Console::WriteLine( "\nWebException is thrown. \nMessage is : {0}", e->Message );
if ( e->Status == WebExceptionStatus::ProtocolError )
{
Console::WriteLine( "Status Code : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusCode );
Console::WriteLine( "Status Description : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusDescription );
Console::WriteLine( "Server : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->Server );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception is thrown. Message is : {0}", e->Message );
}
try {
//Create a web request for "www.msn.com".
HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("http://www.msn.com");
//Get the headers associated with the request.
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
Console.WriteLine("Configuring Webrequest to accept Danish and English language using 'Add' method");
//Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection.Add("Accept-Language:da");
//Include English in the Accept-Langauge header.
myWebHeaderCollection.Add("Accept-Language","en;q=0.8");
//Get the associated response for the above request.
HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
//Print the headers for the request.
printHeaders(myWebHeaderCollection);
myHttpWebResponse.Close();
}
//Catch exception if trying to add a restricted header.
catch(ArgumentException e) {
Console.WriteLine(e.Message);
}
catch(WebException e) {
Console.WriteLine("\nWebException is thrown. \nMessage is :" + e.Message);
if(e.Status == WebExceptionStatus.ProtocolError) {
Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
Console.WriteLine("Server : {0}", ((HttpWebResponse)e.Response).Server);
}
}
catch(Exception e) {
Console.WriteLine("Exception is thrown. Message is :" + e.Message);
}
Public Shared Sub Main()
Try
'Create a web request for "www.msn.com".
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
'Get the headers associated with the request.
Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebRequest.Headers
Console.WriteLine("Configuring Webrequest to accept Danish and English language using 'Add' method")
'Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection.Add("Accept-Language:da")
'Include English in the Accept-Langauge header.
myWebHeaderCollection.Add("Accept-Language","en;q" + ChrW(61) + "0.8")
'Get the associated response for the above request.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'Print the headers for the request.
printHeaders(myWebHeaderCollection)
myHttpWebResponse.Close()
'Catch exception if trying to add a restricted header.
Catch e As ArgumentException
Console.WriteLine(e.Message)
Catch e As WebException
Console.WriteLine(e.Message)
If e.Status = WebExceptionStatus.ProtocolError Then
Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode)
Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription)
Console.WriteLine("Server : {0}", CType(e.Response, HttpWebResponse).Server)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
참고
콜론(:) 뒤의 header문자열인 의 값 부분 길이는 .NET Framework 및 .NET Core 버전 2.0 - 3.1에서만 유효성을 검사합니다.
- 적용 가능한 모든 .NET Framework 버전에서: WebHeaderCollection 속성에서 Headers 반환되는 인스턴스는 값 부분
header의 길이가 65535보다 크면 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 값을 허용합니다. - 버전 3.1을 통한 .NET Core 버전: WebHeaderCollection 형식 HttpResponseHeader 의 헤더와 함께 사용되는 인스턴스는 값 부분
header의 길이가 65535보다 크면 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 값을 허용합니다. - .NET 5 이상 버전: WebHeaderCollection 모든 길이의 값을 허용합니다.
설명
매개 변수는 header "name:value" 형식으로 지정해야 합니다. 지정된 헤더가 컬렉션에 없으면 컬렉션에 새 헤더가 추가됩니다.
에 header 지정된 헤더가 컬렉션에 이미 있는 경우 의 header 값 부분은 기존 값과 연결됩니다.
적용 대상
Add(HttpRequestHeader, String)
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
지정된 값을 가진 지정된 헤더를 컬렉션에 삽입합니다.
public:
void Add(System::Net::HttpRequestHeader header, System::String ^ value);
public void Add (System.Net.HttpRequestHeader header, string? value);
public void Add (System.Net.HttpRequestHeader header, string value);
override this.Add : System.Net.HttpRequestHeader * string -> unit
Public Sub Add (header As HttpRequestHeader, value As String)
매개 변수
- header
- HttpRequestHeader
컬렉션에 추가할 헤더입니다.
- value
- String
헤더의 내용입니다.
예외
.NET Framework 및 .NET Core 버전 2.0 - 3.1만 해당: value의 길이가 65,535자를 넘는 경우
이 WebHeaderCollection 인스턴스에서 HttpRequestHeader의 인스턴스를 사용할 수 없는 경우
설명
지정된 헤더가 없으면 메서드는 Add 헤더 이름/값 쌍 목록에 새 헤더를 삽입합니다.
지정된 헤더가 이미 있는 value 경우 는 헤더와 연결된 값의 쉼표로 구분된 목록에 추가됩니다.
참고
의 value 길이는 .NET Framework 및 .NET Core 버전 2.0 - 3.1에서만 유효성을 검사합니다.
- 적용 가능한 모든 .NET Framework 버전에서: WebHeaderCollection 의 길이
value가 65535보다 크면 속성에서 반환 Headers 되는 인스턴스가 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 을value허용합니다. - 버전 3.1을 통한 .NET Core 버전: WebHeaderCollection 형식 HttpResponseHeader 의 헤더와 함께 사용되는 인스턴스는 길이
value가 65535보다 크면 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 을value허용합니다. - .NET 5 이상 버전: WebHeaderCollection 모든 길이의 을
value허용합니다.
적용 대상
Add(HttpResponseHeader, String)
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
지정된 값을 가진 지정된 헤더를 컬렉션에 삽입합니다.
public:
void Add(System::Net::HttpResponseHeader header, System::String ^ value);
public void Add (System.Net.HttpResponseHeader header, string? value);
public void Add (System.Net.HttpResponseHeader header, string value);
override this.Add : System.Net.HttpResponseHeader * string -> unit
Public Sub Add (header As HttpResponseHeader, value As String)
매개 변수
- header
- HttpResponseHeader
컬렉션에 추가할 헤더입니다.
- value
- String
헤더의 내용입니다.
예외
.NET Framework 및 .NET Core 버전 2.0 - 3.1만 해당: value의 길이가 65,535자를 넘는 경우
이 WebHeaderCollection 인스턴스에서 HttpResponseHeader의 인스턴스를 사용할 수 없는 경우
설명
지정된 헤더가 없으면 메서드는 Add 헤더 이름/값 쌍 목록에 새 헤더를 삽입합니다.
지정된 헤더가 이미 있는 value 경우 는 헤더와 연결된 값의 쉼표로 구분된 목록에 추가됩니다.
참고
의 value 길이는 .NET Framework 및 .NET Core 버전 2.0 - 3.1에서만 유효성을 검사합니다.
- 적용 가능한 모든 .NET Framework 버전에서: WebHeaderCollection 의 길이
value가 65535보다 크면 속성에서 반환 Headers 되는 인스턴스가 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 을value허용합니다. - 버전 3.1을 통한 .NET Core 버전: WebHeaderCollection 형식 HttpResponseHeader 의 헤더와 함께 사용되는 인스턴스는 길이
value가 65535보다 크면 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 을value허용합니다. - .NET 5 이상 버전: WebHeaderCollection 모든 길이의 을
value허용합니다.
적용 대상
Add(String, String)
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
- Source:
- WebHeaderCollection.cs
지정된 이름과 값을 갖고 있는 헤더를 컬렉션에 삽입합니다.
public:
override void Add(System::String ^ name, System::String ^ value);
public override void Add (string name, string? value);
public override void Add (string name, string value);
override this.Add : string * string -> unit
Public Overrides Sub Add (name As String, value As String)
매개 변수
- name
- String
컬렉션에 추가할 헤더입니다.
- value
- String
헤더의 내용입니다.
예외
name이 null 또는 Empty이거나 잘못된 문자를 포함하는 경우
또는
name이 속성 설정을 사용하여 설정해야 하는 제한된 헤더인 경우
또는
value에 잘못된 문자가 들어 있는 경우
.NET Framework 및 .NET Core 버전 2.0 - 3.1만 해당: value의 길이가 65,535자를 넘는 경우
예제
다음 예제에서는 메서드를 사용하여 Add 이름/값 쌍을 에 WebHeaderCollection 추가합니다.
try
{
//Create a web request for S"www.msn.com".
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.msn.com" ));
//Get the headers associated with the request.
WebHeaderCollection^ myWebHeaderCollection = myHttpWebRequest->Headers;
Console::WriteLine( "Configuring Webrequest to accept Danish and English language using 'Add' method" );
//Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection->Add( "Accept-Language:da" );
//Include English in the Accept-Langauge header.
myWebHeaderCollection->Add( "Accept-Language:en;q=0.8" );
//Get the associated response for the above request.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());
//Print the headers for the request.
printHeaders( myWebHeaderCollection );
myHttpWebResponse->Close();
}
//Catch exception if trying to add a restricted header.
catch ( ArgumentException^ e )
{
Console::WriteLine( e->Message );
}
catch ( WebException^ e )
{
Console::WriteLine( "\nWebException is thrown. \nMessage is : {0}", e->Message );
if ( e->Status == WebExceptionStatus::ProtocolError )
{
Console::WriteLine( "Status Code : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusCode );
Console::WriteLine( "Status Description : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusDescription );
Console::WriteLine( "Server : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->Server );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception is thrown. Message is : {0}", e->Message );
}
try {
//Create a web request for "www.msn.com".
HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("http://www.msn.com");
//Get the headers associated with the request.
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
Console.WriteLine("Configuring Webrequest to accept Danish and English language using 'Add' method");
//Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection.Add("Accept-Language:da");
//Include English in the Accept-Langauge header.
myWebHeaderCollection.Add("Accept-Language","en;q=0.8");
//Get the associated response for the above request.
HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
//Print the headers for the request.
printHeaders(myWebHeaderCollection);
myHttpWebResponse.Close();
}
//Catch exception if trying to add a restricted header.
catch(ArgumentException e) {
Console.WriteLine(e.Message);
}
catch(WebException e) {
Console.WriteLine("\nWebException is thrown. \nMessage is :" + e.Message);
if(e.Status == WebExceptionStatus.ProtocolError) {
Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
Console.WriteLine("Server : {0}", ((HttpWebResponse)e.Response).Server);
}
}
catch(Exception e) {
Console.WriteLine("Exception is thrown. Message is :" + e.Message);
}
Public Shared Sub Main()
Try
'Create a web request for "www.msn.com".
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
'Get the headers associated with the request.
Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebRequest.Headers
Console.WriteLine("Configuring Webrequest to accept Danish and English language using 'Add' method")
'Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection.Add("Accept-Language:da")
'Include English in the Accept-Langauge header.
myWebHeaderCollection.Add("Accept-Language","en;q" + ChrW(61) + "0.8")
'Get the associated response for the above request.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'Print the headers for the request.
printHeaders(myWebHeaderCollection)
myHttpWebResponse.Close()
'Catch exception if trying to add a restricted header.
Catch e As ArgumentException
Console.WriteLine(e.Message)
Catch e As WebException
Console.WriteLine(e.Message)
If e.Status = WebExceptionStatus.ProtocolError Then
Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode)
Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription)
Console.WriteLine("Server : {0}", CType(e.Response, HttpWebResponse).Server)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
참고
의 value 길이는 .NET Framework 및 .NET Core 버전 2.0 - 3.1에서만 유효성을 검사합니다.
- 적용 가능한 모든 .NET Framework 버전에서: WebHeaderCollection 의 길이
value가 65535보다 크면 속성에서 반환 Headers 되는 인스턴스가 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 을value허용합니다. - 버전 3.1을 통한 .NET Core 버전: WebHeaderCollection 형식 HttpResponseHeader 의 헤더와 함께 사용되는 인스턴스는 길이
value가 65535보다 크면 을 throw ArgumentOutOfRangeException 합니다. 다른 WebHeaderCollection 모든 인스턴스는 모든 길이의 을value허용합니다. - .NET 5 이상 버전: WebHeaderCollection 모든 길이의 을
value허용합니다.
설명
에 name 지정된 헤더가 없는 경우 메서드는 Add 헤더 이름/값 쌍 목록에 새 헤더를 삽입합니다.
에 name 지정된 헤더가 이미 있는 value 경우 는 와 연결된 기존 쉼표로 구분된 값 목록에 추가됩니다 name.