2010-07-12 5 views

Répondre

62
string contents; 
using (var wc = new System.Net.WebClient()) 
    contents = wc.DownloadString(url); 
+8

Voilà pourquoi je les aime .net libs .. –

+1

Oh bon ... j'espérais que c'était si simple! – John

+0

Comme noté par @CaffGeek, vous voulez disposer du 'WebClient' dans un bloc' using'. – TrueWill

13

Utilisez un WebClient

var result = string.Empty; 
using (var webClient = new System.Net.WebClient()) 
{ 
    result = webClient.DownloadString("http://some.url"); 
} 
+0

Une minute trop tard! –

3

utiliser ce code simplement

var r= string.Empty; 
using (var web = new System.Net.WebClient()) 
     r= web.DownloadString("http://TEST.COM"); 
0
using System.IO; 
using System.Net; 

WebClient client = new WebClient(); 

string dnlad = client.DownloadString("http://www.stackoverflow.com/"); 

File.WriteAllText(@"c:\Users\Admin\Desktop\Data1.txt", dnlad); 

got it de MVA il aide

l'espoir