WebClient.Headers 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
요청과 관련된 헤더 이름/값 쌍의 컬렉션을 가져오거나 설정합니다.
public:
property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); void set(System::Net::WebHeaderCollection ^ value); };
public System.Net.WebHeaderCollection Headers { get; set; }
member this.Headers : System.Net.WebHeaderCollection with get, set
Public Property Headers As WebHeaderCollection
속성 값
이 요청과 관련된 헤더 이름/값 쌍이 들어 있는 WebHeaderCollection입니다.
예제
다음 코드 예제에서는 컬렉션을 사용하여 Headers HTTP Content-Type
헤더를 로 application/x-www-form-urlencoded,
설정하여 양식 데이터가 게시물에 연결되어 있음을 서버에 알립니다.
String^ uriString;
Console::Write( "\nPlease enter the URI to post data to {for example, http://www.contoso.com}: " );
uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:", uriString );
String^ postData = Console::ReadLine();
myWebClient->Headers->Add( "Content-Type", "application/x-www-form-urlencoded" );
// Displays the headers in the request
Console::Write( "Resulting Request Headers: ");
Console::WriteLine(myWebClient->Headers);
// Apply ASCII Encoding to obtain the String^ as a Byte array.
array<Byte>^ byteArray = Encoding::ASCII->GetBytes( postData );
Console::WriteLine( "Uploading to {0} ...", uriString );
// Upload the input String* using the HTTP 1.0 POST method.
array<Byte>^responseArray = myWebClient->UploadData( uriString, "POST", byteArray );
// Decode and display the response.
Console::WriteLine( "\nResponse received was {0}",
Encoding::ASCII->GetString( responseArray ) );
string uriString;
Console.Write("\nPlease enter the URI to post data to {for example, http://www.contoso.com} : ");
uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
string postData = Console.ReadLine();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
// Display the headers in the request
Console.Write("Resulting Request Headers: ");
Console.WriteLine(myWebClient.Headers.ToString());
// Apply ASCII Encoding to obtain the string as a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
Console.WriteLine("Uploading to {0} ...", uriString);
// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
// Decode and display the response.
Console.WriteLine("\nResponse received was {0}",
Encoding.ASCII.GetString(responseArray));
Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to{for example, http://www.contoso.com} : ")
uriString = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the URI {0}:", uriString)
Dim postData As String = Console.ReadLine()
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
' Display the headers in the request
Console.Write("Resulting Request Headers: ")
Console.Writeline(myWebClient.Headers.ToString())
' Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
' Upload the input string using the HTTP 1.0 POST method.
Dim responseArray As Byte() = myWebClient.UploadData(uriString, "POST", byteArray)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}", Encoding.ASCII.GetString(responseArray))
설명
속성은 HeadersWebHeaderCollection 요청과 함께 전송하는 프로토콜 헤더를 WebClient 포함하는 인스턴스를 포함합니다.
일부 일반적인 헤더는 제한된 것으로 간주되며 시스템에 의해 보호되며 개체에서 WebHeaderCollection 설정하거나 변경할 수 없습니다. 개체와 WebClient 연결된 개체에서 WebHeaderCollection 이러한 제한된 헤더 중 하나를 설정하려고 하면 나중에 요청을 보내려고 할 때 예외가 WebClient throw됩니다.
시스템에 의해 보호되는 제한된 헤더에는 다음이 포함되지만 이에 국한되지는 않습니다.
날짜
호스트
또한 개체를 사용할 WebClient 때 다른 헤더도 제한됩니다. 이러한 제한된 헤더에는 다음이 포함되지만 이에 국한되지는 않습니다.
동의함
연결
Content-Length
예상(값이 "100-continue"로 설정된 경우)
If-Modified-Since
범위
Transfer-Encoding
클래스에는 HttpWebRequest 위의 헤더 중 일부를 설정하기 위한 속성이 있습니다. 이러한 헤더를 설정 하는 애플리케이션에 대 한 중요 한 경우 해당 HttpWebRequest 클래스를 대신 사용 해야는 WebRequest 클래스입니다.
웹 서버와 캐시가 웹 요청에 헤더를 변경하거나 추가할 수 있으므로 헤더 값이 변경되지 않은 상태로 유지된다고 가정해서는 안 됩니다.
적용 대상
추가 정보
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기