1 Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Net;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceConsoleApplication79 {Ten class Program One { A Static voidMain (string[] args) - { -WebClient WEBC =NewWebClient (); the stringWebadress =@"http://www.cnblogs.com/"; - stringWebContent =webc.downloadstring (webadress); - Console.WriteLine (webcontent); - Console.readkey (); + } - } +}
2 effects
Garbled ... Why is it? Encoded format!
We check the encoding format of the blog home page
Change the code,
Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Net;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceConsoleApplication79 {Ten class Program One { A Static voidMain (string[] args) - { -WebClient WEBC =NewWebClient (); the stringWebadress =@"http://www.cnblogs.com/"; -Webc.encoding =Encoding.UTF8; - stringWebContent =webc.downloadstring (webadress); - Console.WriteLine (webcontent); + Console.readkey (); - } + } A}
Effect
C # console webcllient download source code for a webpage