HttpWebRequest.GetRequestStream 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
요청 데이터를 쓰는 데 사용할 Stream 개체를 가져옵니다.
오버로드
GetRequestStream() |
요청 데이터를 쓰는 데 사용할 Stream 개체를 가져옵니다. |
GetRequestStream(TransportContext) |
요청 데이터를 쓰는 데 사용하는 Stream 개체를 가져오고 해당 스트림과 연결된 TransportContext를 출력합니다. |
GetRequestStream()
- Source:
- HttpWebRequest.cs
- Source:
- HttpWebRequest.cs
- Source:
- HttpWebRequest.cs
요청 데이터를 쓰는 데 사용할 Stream 개체를 가져옵니다.
public:
override System::IO::Stream ^ GetRequestStream();
public override System.IO.Stream GetRequestStream ();
override this.GetRequestStream : unit -> System.IO.Stream
Public Overrides Function GetRequestStream () As Stream
반환
요청 데이터를 쓰는 데 사용할 Stream입니다.
예외
Method 속성이 GET 또는 HEAD인 경우
또는
KeepAlive가 true
이고, AllowWriteStreamBuffering이 false
이고, ContentLength가 -1이고, SendChunked가 false
이고, Method가 POST 또는 PUT인 경우
요청 캐시 유효성 검사기에서 이 요청에 대한 응답이 캐시에서 제공될 수 있지만 데이터를 쓰는 요청의 경우 캐시를 사용하지 않아야 함을 나타내는 경우. 이 예외는 제대로 구현되지 않은 사용자 지정 캐시 유효성 검사기를 사용하려는 경우에 발생할 수 있습니다.
.NET Compact Framework 애플리케이션에서 콘텐츠 길이가 0인 요청 스트림을 가져오지 않았으며 올바르게 종료되었습니다. 콘텐츠 길이가 0인 요청을 처리하는 방법에 대한 자세한 내용은 .NET Compact Framework의 네트워크 프로그래밍을 참조하세요.
예제
다음 코드 예제에서는 메서드를 GetRequestStream 사용하여 스트림 인스턴스를 반환합니다.
// Set the 'Method' property of the 'Webrequest' to 'POST'.
myHttpWebRequest->Method = "POST";
Console::WriteLine( "\nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :" );
// Create a new String* Object* to POST data to the Url.
String^ inputData = Console::ReadLine();
String^ postData = String::Concat( "firstone= ", inputData );
ASCIIEncoding^ encoding = gcnew ASCIIEncoding;
array<Byte>^ byte1 = encoding->GetBytes( postData );
// Set the content type of the data being posted.
myHttpWebRequest->ContentType = "application/x-www-form-urlencoded";
// Set the content length of the String* being posted.
myHttpWebRequest->ContentLength = byte1->Length;
Stream^ newStream = myHttpWebRequest->GetRequestStream();
newStream->Write( byte1, 0, byte1->Length );
Console::WriteLine( "The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest->ContentLength );
// Close the Stream Object*.
newStream->Close();
// Set the 'Method' property of the 'Webrequest' to 'POST'.
myHttpWebRequest.Method = "POST";
Console.WriteLine ("\nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :");
// Create a new string object to POST data to the Url.
string inputData = Console.ReadLine ();
string postData = "firstone=" + inputData;
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);
// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;
Stream newStream = myHttpWebRequest.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
Console.WriteLine ("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength);
// Close the Stream object.
newStream.Close ();
' Set the 'Method' property of the 'Webrequest' to 'POST'.
myHttpWebRequest.Method = "POST"
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :")
' Create a new string object to POST data to the Url.
Dim inputData As String = Console.ReadLine()
Dim postData As String = "firstone" + ChrW(61) + inputData
Dim encoding As New ASCIIEncoding()
Dim byte1 As Byte() = encoding.GetBytes(postData)
' Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
' Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength)
newStream.Close()
설명
메서드는 GetRequestStream 에 대한 데이터를 보내는 데 사용할 스트림을 반환합니다 HttpWebRequest. 개체가 Stream 반환된 후 메서드를 사용하여 Stream.Write 와 함께 HttpWebRequest 데이터를 보낼 수 있습니다.
애플리케이션의 값을 설정 해야 하는 경우는 ContentLength 속성을이 스트림을 검색 하기 전에 수행 해야 합니다.
메서드를 Stream.Close 호출하여 스트림을 닫고 다시 사용할 연결을 해제해야 합니다. 스트림 닫기에 실패 하면 애플리케이션을 연결에서 실행 합니다.
참고
애플리케이션 특정 요청에 대 한 동기 및 비동기 메서드를 혼합할 수 없습니다. 메서드를 호출하는 GetRequestStream 경우 메서드를 GetResponse 사용하여 응답을 검색해야 합니다.
참고
애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework의 네트워크 추적을 참조하세요.
추가 정보
적용 대상
GetRequestStream(TransportContext)
- Source:
- HttpWebRequest.cs
- Source:
- HttpWebRequest.cs
- Source:
- HttpWebRequest.cs
요청 데이터를 쓰는 데 사용하는 Stream 개체를 가져오고 해당 스트림과 연결된 TransportContext를 출력합니다.
public:
System::IO::Stream ^ GetRequestStream([Runtime::InteropServices::Out] System::Net::TransportContext ^ % context);
public System.IO.Stream GetRequestStream (out System.Net.TransportContext? context);
public System.IO.Stream GetRequestStream (out System.Net.TransportContext context);
override this.GetRequestStream : TransportContext -> System.IO.Stream
Public Function GetRequestStream (ByRef context As TransportContext) As Stream
매개 변수
- context
- TransportContext
TransportContext에 대한 Stream입니다.
반환
요청 데이터를 쓰는 데 사용할 Stream입니다.
예외
GetRequestStream() 메서드는 Stream를 얻을 수 없었습니다.
요청 캐시 유효성 검사기에서 이 요청에 대한 응답이 캐시에서 제공될 수 있지만 데이터를 쓰는 요청의 경우 캐시를 사용하지 않아야 함을 나타내는 경우. 이 예외는 제대로 구현되지 않은 사용자 지정 캐시 유효성 검사기를 사용하려는 경우에 발생할 수 있습니다.
Method 속성이 GET 또는 HEAD인 경우
또는
KeepAlive가 true
이고, AllowWriteStreamBuffering이 false
이고, ContentLength가 -1이고, SendChunked가 false
이고, Method가 POST 또는 PUT인 경우
설명
메서드는 GetRequestStream 에 대한 데이터를 보내는 데 사용할 스트림을 HttpWebRequest 반환하고 스트림과 연결된 을 출력합니다 TransportContext . 개체가 Stream 반환된 후 메서드를 사용하여 Stream.Write 와 함께 HttpWebRequest 데이터를 보낼 수 있습니다.
확장 된 보호를 사용 하 여 통합된 Windows 인증을 사용 하는 일부 애플리케이션에서 사용 하는 전송 계층을 쿼리할 수 해야 HttpWebRequest 기본 TLS 채널에서의 CBT (채널 바인딩 토큰)를 검색 하기 위해. 메서드는 GetRequestStream 요청 본문(POST
및 PUT
요청)이 있는 HTTP 메서드에 대해 이 정보에 대한 액세스를 제공합니다. 애플리케이션에서 자체 인증을 구현 하는 CBT에 액세스 해야 하는 경우에 필요 합니다.
애플리케이션의 값을 설정 해야 하는 경우는 ContentLength 속성을이 스트림을 검색 하기 전에 수행 해야 합니다.
메서드를 Stream.Close 호출하여 스트림을 닫고 다시 사용할 연결을 해제해야 합니다. 스트림 닫기에 실패 하면 애플리케이션을 연결에서 실행 합니다.
참고
애플리케이션 특정 요청에 대 한 동기 및 비동기 메서드를 혼합할 수 없습니다. 메서드를 호출하는 GetRequestStream 경우 메서드를 GetResponse 사용하여 응답을 검색해야 합니다.
참고
애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework의 네트워크 추적을 참조하세요.
추가 정보
- TransportContext
- GetChannelBinding(ChannelBindingKind)
- System.Security.Authentication.ExtendedProtection
- ChannelBinding
- 확장된 보호를 사용하는 Windows 통합 인증(Integrated Windows Authentication with Extended Protection)
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기