ערוך

שתף באמצעות


WebClient.DownloadString Method

Definition

Downloads the requested resource as a String. The resource to download may be specified as either String containing the URI or a Uri.

Overloads

DownloadString(String)

Downloads the requested resource as a String. The resource to download is specified as a String containing the URI.

DownloadString(Uri)

Downloads the requested resource as a String. The resource to download is specified as a Uri.

DownloadString(String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Downloads the requested resource as a String. The resource to download is specified as a String containing the URI.

public:
 System::String ^ DownloadString(System::String ^ address);
public string DownloadString (string address);
member this.DownloadString : string -> string
Public Function DownloadString (address As String) As String

Parameters

address
String

A String containing the URI to download.

Returns

A String containing the requested resource.

Exceptions

The address parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

An error occurred while downloading the resource.

The method has been called simultaneously on multiple threads.

Examples

The following code example demonstrates calling this method.

void DownloadString( String^ address )
{
   WebClient^ client = gcnew WebClient;
   String^ reply = client->DownloadString( address );
   Console::WriteLine( reply );
}


public static void DownloadString(string address)
{
    WebClient client = new WebClient();
    string reply = client.DownloadString(address);

    Console.WriteLine(reply);
}
Public Shared Sub DownloadString(ByVal address As String)

    Dim client As WebClient = New WebClient()
    Dim reply As String = client.DownloadString(address)

    Console.WriteLine(reply)
End Sub


Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method retrieves the specified resource. After it downloads the resource, the method uses the encoding specified in the Encoding property to convert the resource to a String. This method blocks while downloading the resource. To download a resource and continue executing while waiting for the server's response, use one of the DownloadStringAsync methods.

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. If the QueryString property is not an empty string, it is appended to address.

This method uses the RETR command to download an FTP resource. For an HTTP resource, the GET method is used.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.

Applies to

DownloadString(Uri)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Downloads the requested resource as a String. The resource to download is specified as a Uri.

public:
 System::String ^ DownloadString(Uri ^ address);
public string DownloadString (Uri address);
member this.DownloadString : Uri -> string
Public Function DownloadString (address As Uri) As String

Parameters

address
Uri

A Uri object containing the URI to download.

Returns

A String containing the requested resource.

Exceptions

The address parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

An error occurred while downloading the resource.

The method has been called simultaneously on multiple threads.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method retrieves the specified resource. After it downloads the resource, the method uses the encoding specified in the Encoding property to convert the resource to a String. This method blocks while downloading the resource. To download a resource and continue executing while waiting for the server's response, use one of the DownloadStringAsync methods.

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. If the QueryString property is not an empty string, it is appended to address.

This method uses the RETR command to download an FTP resource. For an HTTP resource, the GET method is used.

Note

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.

Applies to