FtpWebRequest.EndGetResponse Method
Ends a pending asynchronous operation started with BeginGetResponse.
Namespace: System.Net
Assembly: System (in System.dll)
Parameters
- asyncResult
- Type: System.IAsyncResult
The IAsyncResult that was returned when the operation started.
Return Value
Type: System.Net.WebResponseA WebResponse reference that contains an FtpWebResponse instance. This object contains the FTP server's response to the request.
| Exception | Condition |
|---|---|
| ArgumentNullException | asyncResult is null. |
| ArgumentException | asyncResult was not obtained by calling BeginGetResponse. |
| InvalidOperationException | This method was already called for the operation identified by asyncResult. |
| WebException | An error occurred using an HTTP proxy. |
If the operation has not completed at the time the EndGetResponse method is called, EndGetResponse blocks until the operation completes. To prevent blocking, check the IsCompleted property before calling EndGetResponse.
In addition to the exceptions noted in "Exceptions," EndGetResponse rethrows exceptions that were thrown while communicating with the server.
Note |
|---|
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing. |
This method generates network traffic.
The following code example demonstrates ending an asynchronous operation to get a response. This code example is part of a larger example provided for the FtpWebRequest class overview.
// 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(); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note