2010-07-12 12 views

risposta

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

Questo è il motivo per cui amo le librerie .net .. –

+1

Oh bene ... speravo fosse così facile! – John

+0

Come indicato da @CaffGeek, si desidera disporre di 'WebClient' in un blocco' using'. – TrueWill

13

Utilizzare un WebClient

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

Un minuto troppo tardi! –

3

utilizzare questo codice Semplicemente

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); 

preso da MVA spero che aiuta