WebClient.DownloadData Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Télécharge la ressource en tant que tableau Byte à partir de l'URI spécifié.
Surcharges
DownloadData(String) |
Télécharge la ressource en tant que tableau Byte à partir de l'URI spécifié. |
DownloadData(Uri) |
Télécharge la ressource en tant que tableau Byte à partir de l'URI spécifié. |
DownloadData(String)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
Télécharge la ressource en tant que tableau Byte à partir de l'URI spécifié.
public:
cli::array <System::Byte> ^ DownloadData(System::String ^ address);
public byte[] DownloadData (string address);
member this.DownloadData : string -> byte[]
Public Function DownloadData (address As String) As Byte()
Paramètres
- address
- String
URI à partir duquel télécharger des données.
Retours
Tableau de Byte contenant la ressource téléchargée.
Exceptions
Le paramètre address
a la valeur null
.
L'URI formé en combinant la propriété BaseAddress et address
n'est pas valide.
- ou -
Une erreur s'est produite lors du téléchargement de données.
La méthode a été appelée sur plusieurs threads simultanément.
Exemples
L’exemple de code suivant demande des données à partir d’un serveur et affiche les données retournées. Il suppose que remoteUri
contient un URI valide pour les données demandées.
Console::Write( "\nPlease enter a URI (e.g. http://www.contoso.com): " );
String^ remoteUri = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
// Download home page data.
Console::WriteLine( "Downloading {0}", remoteUri );
// Download the Web resource and save it into a data buffer.
array<Byte>^ myDataBuffer = myWebClient->DownloadData( remoteUri );
// Display the downloaded data.
String^ download = Encoding::ASCII->GetString( myDataBuffer );
Console::WriteLine( download );
Console::WriteLine( "Download successful." );
Console.Write("\nPlease enter a URI (for example, http://www.contoso.com): ");
string remoteUri = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Download home page data.
Console.WriteLine("Downloading " + remoteUri);
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);
// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDataBuffer);
Console.WriteLine(download);
Console.WriteLine("Download successful.");
Console.Write(ControlChars.Cr + "Please enter a Url(for example, http://www.msn.com): ")
Dim remoteUrl As String = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Download the home page data.
Console.WriteLine(("Downloading " + remoteUrl))
' DownloadData() method takes a 'uriRemote.ToString()' and downloads the Web resource and saves it into a data buffer.
Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)
' Display the downloaded data.
Dim download As String = Encoding.ASCII.GetString(myDataBuffer)
Console.WriteLine(download)
Console.WriteLine("Download successful.")
Remarques
La DownloadData méthode télécharge la ressource avec l’URI spécifié par le address
paramètre . Cette méthode se bloque lors du téléchargement de la ressource. Pour télécharger une ressource et poursuivre l’exécution en attendant la réponse du serveur, utilisez l’une DownloadDataAsync des méthodes .
Si la BaseAddress propriété n’est pas une chaîne vide (« ») et address
ne contient pas d’URI absolu, address
doit être un URI relatif qui est combiné avec BaseAddress pour former l’URI absolu des données demandées. Si la QueryString propriété n’est pas une chaîne vide, elle est ajoutée à address
.
Cette méthode utilise la commande RETR pour télécharger une ressource FTP. Pour une ressource HTTP, la méthode GET est utilisée.
Notes
Ce membre génère des informations de traçage lorsque vous activez le traçage réseau dans votre application. Pour plus d’informations, consultez Suivi réseau dans .NET Framework.
S’applique à
DownloadData(Uri)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
Télécharge la ressource en tant que tableau Byte à partir de l'URI spécifié.
public:
cli::array <System::Byte> ^ DownloadData(Uri ^ address);
public byte[] DownloadData (Uri address);
member this.DownloadData : Uri -> byte[]
Public Function DownloadData (address As Uri) As Byte()
Paramètres
Retours
Tableau de Byte contenant la ressource téléchargée.
Exceptions
Le paramètre address
a la valeur null
.
Remarques
La DownloadData méthode télécharge la ressource avec l’URI spécifié par le address
paramètre . Cette méthode se bloque lors du téléchargement de la ressource. Pour télécharger une ressource et poursuivre l’exécution en attendant la réponse du serveur, utilisez l’une DownloadDataAsync des méthodes .
Si la BaseAddress propriété n’est pas une chaîne vide (« ») et address
ne contient pas d’URI absolu, address
doit être un URI relatif qui est combiné avec BaseAddress pour former l’URI absolu des données demandées. Si la QueryString propriété n’est pas une chaîne vide, elle est ajoutée à address
.
Cette méthode utilise la commande RETR pour télécharger une ressource FTP. Pour une ressource HTTP, la méthode GET est utilisée.
Notes
Ce membre génère des informations de traçage lorsque vous activez le traçage réseau dans votre application. Pour plus d’informations, consultez Suivi réseau dans .NET Framework.
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de l’année 2024, nous abandonnerons progressivement le mécanisme de retour d’information GitHub Issues pour le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultez :Soumettre et afficher des commentaires pour