FtpWebRequest.EndGetResponse(IAsyncResult) Método

Definição

Encerra uma operação assíncrona pendente iniciada com BeginGetResponse(AsyncCallback, Object).Ends a pending asynchronous operation started with BeginGetResponse(AsyncCallback, Object).

public:
 override System::Net::WebResponse ^ EndGetResponse(IAsyncResult ^ asyncResult);
public override System.Net.WebResponse EndGetResponse (IAsyncResult asyncResult);
override this.EndGetResponse : IAsyncResult -> System.Net.WebResponse
Public Overrides Function EndGetResponse (asyncResult As IAsyncResult) As WebResponse

Parâmetros

asyncResult
IAsyncResult

O IAsyncResult retornado quando a operação foi iniciada.The IAsyncResult that was returned when the operation started.

Retornos

WebResponse

Uma referência WebResponse que contém uma instância FtpWebResponse.A WebResponse reference that contains an FtpWebResponse instance. Esse objeto contém a resposta do servidor FTP para a solicitação.This object contains the FTP server's response to the request.

Exceções

asyncResult é null.asyncResult is null.

asyncResult não foi obtido chamando BeginGetResponse(AsyncCallback, Object).asyncResult was not obtained by calling BeginGetResponse(AsyncCallback, Object).

Esse método já foi chamado para a operação identificada por asyncResult.This method was already called for the operation identified by asyncResult.

Ocorreu um erro usando um proxy HTTP.An error occurred using an HTTP proxy.

Exemplos

O exemplo de código a seguir demonstra como encerrar uma operação assíncrona para obter uma resposta.The following code example demonstrates ending an asynchronous operation to get a response. Este exemplo de código é parte de um exemplo maior fornecido para a FtpWebRequest visão geral da classe.This code example is part of a larger example provided for the FtpWebRequest class overview.

// The EndGetResponseCallback method  
// completes a call to BeginGetResponse.
static void EndGetResponseCallback( IAsyncResult^ ar )
{
   FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
   FtpWebResponse ^ response = nullptr;
   try
   {
      response = dynamic_cast<FtpWebResponse^>(state->Request->EndGetResponse( ar ));
      response->Close();
      state->StatusDescription = response->StatusDescription;

      // Signal the main application thread that 
      // the operation is complete.
      state->OperationComplete->Set();
   }
   // Return exceptions to the main application thread.
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Error getting response." );
      state->OperationException = e;
      state->OperationComplete->Set();
   }
}
// The EndGetResponseCallback method
// completes a call to BeginGetResponse.
private static void EndGetResponseCallback(IAsyncResult ar)
{
    FtpState state = (FtpState) ar.AsyncState;
    FtpWebResponse response = null;
    try
    {
        response = (FtpWebResponse) state.Request.EndGetResponse(ar);
        response.Close();
        state.StatusDescription = response.StatusDescription;
        // Signal the main application thread that
        // the operation is complete.
        state.OperationComplete.Set();
    }
    // Return exceptions to the main application thread.
    catch (Exception e)
    {
        Console.WriteLine ("Error getting response.");
        state.OperationException = e;
        state.OperationComplete.Set();
    }
}

Comentários

Se a operação não tiver sido concluída no momento em EndGetResponse que o método for chamado, o EndGetResponse bloqueará até que a operação seja concluída.If the operation has not completed at the time the EndGetResponse method is called, EndGetResponse blocks until the operation completes. Para impedir o bloqueio, verifique a IsCompleted propriedade antes de chamar EndGetResponse .To prevent blocking, check the IsCompleted property before calling EndGetResponse.

Além das exceções observadas em "exceções", o EndGetResponse relança as exceções que foram geradas durante a comunicação com o servidor.In addition to the exceptions noted in "Exceptions," EndGetResponse rethrows exceptions that were thrown while communicating with the server.

Observação

Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede na .NET Framework.For more information, see Network Tracing in the .NET Framework.

Notas aos Chamadores

Esse método gera o tráfego de rede.This method generates network traffic.

Aplica-se a

Confira também