WebClient.DownloadDataAsync 方法

定义

从指定 URI 中将资源作为 Byte 数组下载以作为异步操作。Downloads the resource as a Byte array from the URI specified as an asynchronous operation. 这些方法不阻止调用线程。These methods do not block the calling thread.

重载

DownloadDataAsync(Uri)

从指定 URI 中将资源作为 Byte 数组下载以作为异步操作。Downloads the resource as a Byte array from the URI specified as an asynchronous operation.

DownloadDataAsync(Uri, Object)

从指定 URI 中将资源作为 Byte 数组下载以作为异步操作。Downloads the resource as a Byte array from the URI specified as an asynchronous operation.

DownloadDataAsync(Uri)

从指定 URI 中将资源作为 Byte 数组下载以作为异步操作。Downloads the resource as a Byte array from the URI specified as an asynchronous operation.

public:
 void DownloadDataAsync(Uri ^ address);
public void DownloadDataAsync (Uri address);
member this.DownloadDataAsync : Uri -> unit
Public Sub DownloadDataAsync (address As Uri)

参数

address
Uri

包含要下载的 URI 的 UriA Uri containing the URI to download.

异常

address 参数为 nullThe address parameter is null.

通过组合 BaseAddressaddress 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.

-或--or- 下载资源时出现错误。An error occurred while downloading the resource.

注解

此方法使用与 address中指定的 URI 方案关联的协议的默认方法检索指定的资源。This method retrieves the specified resource using the default method for the protocol associated with the URI scheme specified in address. 使用自动从线程池分配的线程资源异步下载数据。The data is downloaded asynchronously using thread resources that are automatically allocated from the thread pool.

此方法在下载资源时不会阻止调用线程。This method does not block the calling thread while downloading the resource. 若要下载资源并在等待服务器响应时阻止,请使用 DownloadData 方法之一。To download a resource and block while waiting for the server's response, use one of the DownloadData methods. 下载完成后,将引发 DownloadDataCompleted 事件。When the download completes, the DownloadDataCompleted event is raised. 应用程序必须处理此事件才能接收通知。Your application must handle this event to receive notification. 下载的数据在 Result 属性中提供。The downloaded data is available in the Result property.

您可以使用 CancelAsync 方法来取消尚未完成的异步操作。You can use the CancelAsync method to cancel asynchronous operations that have not completed.

此方法使用 RETR 命令下载 FTP 资源。This method uses the RETR command to download an FTP resource. 对于 HTTP 资源,使用 GET 方法。For an HTTP resource, the GET method is used.

如果 BaseAddress 属性不是空字符串("")且 address 不包含绝对 URI,address 必须是与 BaseAddress 组合在一起的相对 URI,才能形成所请求数据的绝对 URI。If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果 QueryString 属性不是空字符串,则会将其追加到 address中。If the QueryString property is not an empty string, it is appended to address.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅.NET Framework 中的网络跟踪For more information, see Network Tracing in the .NET Framework.

DownloadDataAsync(Uri, Object)

从指定 URI 中将资源作为 Byte 数组下载以作为异步操作。Downloads the resource as a Byte array from the URI specified as an asynchronous operation.

public:
 void DownloadDataAsync(Uri ^ address, System::Object ^ userToken);
public void DownloadDataAsync (Uri address, object userToken);
member this.DownloadDataAsync : Uri * obj -> unit
Public Sub DownloadDataAsync (address As Uri, userToken As Object)

参数

address
Uri

包含要下载的 URI 的 UriA Uri containing the URI to download.

userToken
Object

一个用户定义对象,此对象将传递给完成异步操作后所调用的方法。A user-defined object that is passed to the method invoked when the asynchronous operation completes.

异常

address 参数为 nullThe address parameter is null.

通过组合 BaseAddressaddress 所构成的 URI 无效。The URI formed by combining BaseAddress and address is invalid.

-或--or- 下载资源时出现错误。An error occurred while downloading the resource.

注解

此方法使用与 address中指定的 URI 方案关联的协议的默认方法检索指定的资源。This method retrieves the specified resource using the default method for the protocol associated with the URI scheme specified in address. 使用自动从线程池分配的线程资源异步下载数据。The data is downloaded asynchronously using thread resources that are automatically allocated from the thread pool.

此方法在下载资源时不会阻止调用线程。This method does not block the calling thread while downloading the resource. 若要下载资源并在等待服务器响应时阻止,请使用 DownloadData 方法之一。To download a resource and block while waiting for the server's response, use one of the DownloadData methods. 下载完成后,将引发 DownloadDataCompleted 事件。When the download completes, the DownloadDataCompleted event is raised. 应用程序必须处理此事件才能接收通知。Your application must handle this event to receive notification. 下载的数据在 Result 属性中提供。The downloaded data is available in the Result property.

您可以使用 CancelAsync 方法来取消尚未完成的异步操作。You can use the CancelAsync method to cancel asynchronous operations that have not completed.

此方法使用 RETR 命令下载 FTP 资源。This method uses the RETR command to download an FTP resource. 对于 HTTP 资源,使用 GET 方法。For an HTTP resource, the GET method is used.

如果 BaseAddress 属性不是空字符串("")且 address 不包含绝对 URI,address 必须是与 BaseAddress 组合在一起的相对 URI,才能形成所请求数据的绝对 URI。If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. 如果 QueryString 属性不是空字符串,则会将其追加到 address中。If the QueryString property is not an empty string, it is appended to address.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅.NET Framework 中的网络跟踪For more information, see Network Tracing in the .NET Framework.

适用于