FtpWebRequest.BeginGetResponse(AsyncCallback, Object) Yöntem

Tanım

zaman uyumsuz olarak bir FTP sunucusundan istek göndermeye ve yanıt almaya başlar.

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

Parametreler

callback
AsyncCallback

AsyncCallback İşlem tamamlandığında çağırma yöntemine başvuran bir temsilci.

state
Object

İşlem hakkında bilgi içeren kullanıcı tanımlı bir nesne. İşlem tamamlandığında bu nesne temsilciye callback geçirilir.

Döndürülenler

IAsyncResult İşlemin durumunu gösteren örnek.

Özel durumlar

Örnekler

Aşağıdaki kod örneği, bir isteğin akışını almak için zaman uyumsuz bir işlemi sonlandırmayı ve ardından yanıtı almak için bir istek başlatmayı gösterir. Bu kod örneği, sınıfa genel bakış için FtpWebRequest sağlanan daha büyük bir örneğin bir parçasıdır.

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;
    }
}

Açıklamalar

yöntemini çağırarak EndGetResponse zaman uyumsuz işlemi tamamlamanız gerekir. Genellikle, EndGetResponse tarafından başvurulan yöntem tarafından callbackçağrılır. İşlemin durumunu belirlemek için yöntemi tarafından BeginGetResponse döndürülen nesnedeki IAsyncResult özellikleri denetleyin.

Proxy Özellik doğrudan veya bir yapılandırma dosyasında ayarlanırsa, FTP sunucusuyla iletişim belirtilen ara sunucu üzerinden yapılır.

BeginGetResponse sunucudan yanıt beklerken engellemez. Engellemek için yerine yöntemini çağırın GetResponseBeginGetResponse.

Zaman uyumsuz programlama modelini kullanma hakkında daha fazla bilgi için bkz. Zaman Uyumlu Yöntemleri Zaman Uyumsuz Olarak Çağırma.

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için .NET Framework ağ izleme bölümüne bakın.

Not

oluşturulursa WebException , sunucudan Response yanıtı belirlemek için özel durumun ve Status özelliklerini kullanın.

Arayanlara Notlar

Bu yöntem ağ trafiği oluşturur.

Şunlara uygulanır

Ayrıca bkz.