FtpWebRequest.BeginGetResponse メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FtpWebRequest.BeginGetResponse メソッドの意味・解説 

FtpWebRequest.BeginGetResponse メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

要求非同期的な送信と、FTP サーバーからの応答非同期的な受信開始します

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Overrides Function
 BeginGetResponse ( _
    callback As AsyncCallback, _
    state As Object _
) As IAsyncResult
Dim instance As FtpWebRequest
Dim callback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginGetResponse(callback, state)
public override IAsyncResult BeginGetResponse (
    AsyncCallback callback,
    Object state
)
public:
virtual IAsyncResult^ BeginGetResponse (
    AsyncCallback^ callback, 
    Object^ state
) override
public IAsyncResult BeginGetResponse (
    AsyncCallback callback, 
    Object state
)
public override function BeginGetResponse (
    callback : AsyncCallback, 
    state : Object
) : IAsyncResult

パラメータ

callback

操作完了時に呼び出すメソッド参照する AsyncCallback デリゲート

state

操作に関する情報格納するユーザー定義のオブジェクト。このオブジェクトは、操作完了時に callback デリゲート渡されます。

戻り値
操作の状態を示す IAsyncResult インスタンス

例外例外
例外種類条件

InvalidOperationException

GetResponse または BeginGetResponse は、このインスタンスに対して既に呼び出されています。

解説解説
使用例使用例

要求ストリーム取得するための非同期操作終了してから、応答取得する要求開始するコード例次に示します。このコード例は FtpWebRequest クラス概要取り上げているコード例一部分です。

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;
    }
   
}
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;
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FtpWebRequest クラス
FtpWebRequest メンバ
System.Net 名前空間
FtpWebResponse
FtpStatusCode 列挙
WebRequestMethods.Ftp
WebRequest
WebResponse
WebClient


このページでは「.NET Framework クラス ライブラリ リファレンス」からFtpWebRequest.BeginGetResponse メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からFtpWebRequest.BeginGetResponse メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFtpWebRequest.BeginGetResponse メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

FtpWebRequest.BeginGetResponse メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FtpWebRequest.BeginGetResponse メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS