FtpWebRequest.BeginGetResponse(AsyncCallback, Object) 메서드

정의

비동기적으로 FTP 서버에 요청을 보내고 응답을 받는 작업을 시작합니다.

public:
 override IAsyncResult ^ BeginGetResponse(AsyncCallback ^ callback, System::Object ^ state);
public override IAsyncResult BeginGetResponse (AsyncCallback? callback, object? state);
public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state);
override this.BeginGetResponse : AsyncCallback * obj -> IAsyncResult
Public Overrides Function BeginGetResponse (callback As AsyncCallback, state As Object) As IAsyncResult

매개 변수

callback
AsyncCallback

작업이 완료되었을 때 호출할 메서드를 참조하는 AsyncCallback 대리자입니다.

state
Object

작업에 대한 정보가 들어 있는 사용자 정의 개체입니다. 작업이 완료되면 callback 대리자에게 전달되는 개체입니다.

반환

작업의 상태를 나타내는 IAsyncResult 인스턴스입니다.

예외

GetResponse() 또는 BeginGetResponse(AsyncCallback, Object)가 이 인스턴스에 대해 이미 호출된 경우

예제

다음 코드 예제에서는 요청의 스트림을 가져오기 위해 비동기 작업을 종료한 다음 응답을 가져오기 위한 요청을 시작하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 FtpWebRequest 클래스 개요입니다.

private:
   static void EndGetStreamCallback( IAsyncResult^ ar )
   {
      FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
      Stream^ requestStream = nullptr;

      // End the asynchronous call to get the request stream.
      try
      {
         requestStream = state->Request->EndGetRequestStream( ar );

         // Copy the file contents to the request stream.
         const int bufferLength = 2048;
         array<Byte>^buffer = gcnew array<Byte>(bufferLength);
         int count = 0;
         int readBytes = 0;
         FileStream^ stream = File::OpenRead( state->FileName );
         do
         {
            readBytes = stream->Read( buffer, 0, bufferLength );
            requestStream->Write( buffer, 0, bufferLength );
            count += readBytes;
         }
         while ( readBytes != 0 );
         Console::WriteLine( "Writing {0} bytes to the stream.", count );

         // IMPORTANT: Close the request stream before sending the request.
         requestStream->Close();

         // Asynchronously get the response to the upload request.
         state->Request->BeginGetResponse( gcnew AsyncCallback( EndGetResponseCallback ), state );
      }
      // Return exceptions to the main application thread.
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Could not get the request stream." );
         state->OperationException = e;
         state->OperationComplete->Set();
         return;
      }
   }
private static void EndGetStreamCallback(IAsyncResult ar)
{
    FtpState state = (FtpState) ar.AsyncState;

    Stream requestStream = null;
    // End the asynchronous call to get the request stream.
    try
    {
        requestStream = state.Request.EndGetRequestStream(ar);
        // Copy the file contents to the request stream.
        const int bufferLength = 2048;
        byte[] buffer = new byte[bufferLength];
        int count = 0;
        int readBytes = 0;
        FileStream stream = File.OpenRead(state.FileName);
        do
        {
            readBytes = stream.Read(buffer, 0, bufferLength);
            requestStream.Write(buffer, 0, readBytes);
            count += readBytes;
        }
        while (readBytes != 0);
        Console.WriteLine ("Writing {0} bytes to the stream.", count);
        // IMPORTANT: Close the request stream before sending the request.
        requestStream.Close();
        // Asynchronously get the response to the upload request.
        state.Request.BeginGetResponse(
            new AsyncCallback (EndGetResponseCallback),
            state
        );
    }
    // Return exceptions to the main application thread.
    catch (Exception e)
    {
        Console.WriteLine("Could not get the request stream.");
        state.OperationException = e;
        state.OperationComplete.Set();
        return;
    }
}

설명

메서드를 호출 EndGetResponse 하여 비동기 작업을 완료해야 합니다. 일반적으로 는 EndGetResponse 에서 참조하는 메서드에 의해 callback호출됩니다. 작업의 상태를 확인하려면 메서드에서 반환 BeginGetResponse 된 개체의 IAsyncResult 속성을 검사.

속성이 Proxy 직접 또는 구성 파일에서 설정된 경우 FTP 서버와의 통신은 지정된 프록시를 통해 이루어집니다.

BeginGetResponse 는 서버의 응답을 기다리는 동안 차단되지 않습니다. 차단하려면 대신 메서드를 GetResponse 호출합니다 BeginGetResponse.

비동기 프로그래밍 모델 사용에 대한 자세한 내용은 동기 메서드 비동기 호출을 참조하세요.

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

참고

WebException throw되면 예외의 ResponseStatus 속성을 사용하여 서버의 응답을 확인합니다.

호출자 참고

이 메서드는 네트워크 트래픽을 생성합니다.

적용 대상

추가 정보