c# - WebClient.DownloadString(url) won't work for urls that are in uni-code characters such as persian -


i trying html content url has persian characters in such as:

http://example.com/%d8%b7%d8%b1%d8%a7%d8%ad%db%8c-%d9%88%d8%a8-%d8%b3%d8%a7%db%8c%d8%aa-%d8%a2%d8%aa%d9%84%db%8c%d9%87/website/atelier

i using code:

using (webclient client = new webclient()) {     client.encoding = encoding.utf8;     string data = client.downloadstring(urltextwithpersiancharacters); } 

when url this, unreadable characters , symbols. code fine other websites have english urls , persian content.

edit: both answers worked find testing other websites. problem 1 specific website trying content. can website block these kinds of requests?or use other encodings maybe?

what suggest me do?

try convert url string uri:

       uri uri = new uri("http://example.com/%d8%b7%d8%b1%d8%a7%d8%ad%db%8c-%d9%88%d8%a8-%d8%b3%d8%a7%db%8c%d8%aa-%d8%a2%d8%aa%d9%84%db%8c%d9%87/website/atelier"); using (webclient client = new webclient()) {     client.encoding = encoding.utf8;     string data = client.downloadstring(uri); } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -