[英]WebClient.DownloadString() method returns special characters
My application is an asp.net
application. 我的应用程序是一个asp.net
应用程序。 To make it very simple I have one.aspx
which simply writes hello. 为了使它非常简单,我有one.aspx
,它只是简单地写你好。 This works fine when executed in the URL
. 这在URL
执行时工作正常。
Now I have two.aspx
and have the following code : 现在我有two.aspx
并有以下代码:
string downloadurl = String.Format(@"http://{0}", rawUrl.Authority + "1.aspx");
using (var webClient = new System.Net.WebClient())
{
webClient.Encoding = System.Text.Encoding.ASCII;
webClient.Headers.Add("Content-Type", "text/html; charset=ISO-8859-1");
result = webClient.DownloadString(downloadurl);
}
contentpage.InnerHtml = result;
The code essentially downloads the 1.aspx
output in the html
format. 该代码基本上以html
格式下载1.aspx
输出。
This is where I get an error. 这是我收到错误的地方。 The result is a set of some special characters, instead of the output Hello. 结果是一组特殊字符,而不是输出Hello。 I tried UTF-8
and ASCII
, but nothing seems to work. 我尝试过UTF-8
和ASCII
,但似乎没什么用。
Output 产量
"\‹\\b\\0\\0\\0\\0\\0\\\0\QMo‚@\½7é\Øì\p\ÓX\h\tK=P\\"\´^\\f”]Ùò± ‹Â¿\Ô\¦\ç2y3ïeÞÌh”\\\nP\'òD‡\o\\ѯ`¼Ôá\\f…ŒœV-iF<‹šª{ß³DW$\\t‚!ÃQ+÷ç'\•U+€è+¢Ã”%\\t)!(£b@»]¸Äk?0\|\Ý\ŽQÞ\¤Ø¢Õb^ÒÂWPM‰›Õ‹ìäl~\Yvv@×fÊ\îC„|³RLc»ì1yÁ'yî\–ºíë¿8u£žºÔD¼ñ¼\QjÕ'-ûÞ^‡\\0\\r\\õhãoì\\ëý3;éÜ\\«'õùª(êu\¸…–°ã\ŽñEòœO\èž2*.ÓÄpiø¸VCã\.Ë\\LM4oÇ\\\0\\0" “\\ u001f <\\ B \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ U0004 \\ 0 \\ u008dQMo,@ \½7é\Øì\\ u000fp \ÓX\\ u0012h \\ u0003tK = P \\“\\ u0010' ^ \\ F”] UO± <¿\Ô\\ u0003| \ç2y3ïeÞÌh” \\ u001f \\为nP \'òD‡\\ u0015o \\ U0004 \ѯ`¼Ôá\\ F的ŒœV-IF <<šª{ß³DW$ \\ T,!AQ + A·C “\\ u008d•U +€E +¢A”%\\吨)(£b @»] AK 0 \\ U0002 |!?\Ý\ŽQÞ\¤Ø¢OB ^ÒÂWPM‰>Õ<IAL〜\\ u000eYvv @ ×FE \îC“|³RLc»ì1yÁ'yî\\ U0004-ºíë¿8u£žºÔD¼ñ¼\QjÕ'-UTH ^‡\\ 0 \\ r \\ u000e \õhãoì\\ u0019 \ëý3; EU \\«'õùª(EU \\ U0002 ... - °A \ŽñEòœO\èž2*.ÓÄpiø¸VCã\.Ë\\ u009d \LM4oÇ\\ U0001 \\ 0 \\ 0"
You need to define the content type and utf format 您需要定义内容类型和utf格式
https://dotnetfiddle.net/eIdm1D https://dotnetfiddle.net/eIdm1D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.