.net6环境下RestSharp获取gbk网页乱码的解决方案

Hello friends social networking, on this occasion the admin wants to share an article entitled .net6环境下RestSharp获取gbk网页乱码的解决方案 , we have made good, quality and useful articles for you to read and take information in. hopefully the post content is about which we write you can understand. Alright, happy reading.
  public IActionResult GetHiPda()  {   cookies = @"__utmz=128828693.1622702936.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); cdb_cookietime=2592000; cdb_auth=fd05ACWP2GIZl8k0oqBaZUtQ8WjXIxIXESeqpdSfAzikXEX4tYdJM%2B4FIBRY7jXLyGQs0yjP3K2kgFK6MFe6fcJkrIH5; smile=1D1; discuz_fastpostrefresh=0; __utmc=128828693; cdb_visitedfid=2D6; cdb_sid=0ZwKQ7; __utma=128828693.1700824799.1622702936.1623767772.1623808037.73; __utmt=1; __utmb=128828693.1.10.1623808037; checkpm=1";   string url = @"https://www.hi-pda.com/forum/forumdisplay.php?fid=2";   var client = new RestClient(url);   var request = new RestRequest();   request.AddHeader("cookie", cookies);   var response = client.Get(request);   Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);   var data=HttpUtility.UrlDecode(response.RawBytes, Encoding.GetEncoding("gbk"));   return Content(data);  }

引入NuGet包:System.Text.Encoding.CodePages

CLR中的Encoding就是用于字节和字符之间的转换的。

CLR中的Encoding是在System.Text命名空间下的,它是一个抽象类(abstract class),  所以不能被直接实例化,它主要有如下的派生类:ASCIIEnding,UnicodeEncoding,UTF32Encoding,UTF7Encoding,UTF8Encoding,你可以根据需要选择一个合适的Encoding来进行编码和解码。你也可以调用Encoding的静态属性ASCII,Unicode,UTF32,UTF7,UTF8,来构造一个Encoding。其中Unicode是表示16位Encoding。调用静态属性和实例化一个子类的效果是一样的,如下代码。

1 Encoding encodingUTF8 = Encoding.UTF8;
2 Encoding encodingUTF8 = new UTF8Encoding(true);

以下是这些类型的一些简单描述:

    ASCII编码  将16位字符编码成ASCII码,只能转换值小于Ox0080的16字符,并且被转换成单字节,就是说一个字符对应一个字节。当字符都在ASCII范围(0X00~0X7F)内时,可以用这种编码,它的速度非常快,适合于英美地区的字符。这种编码非常有限,汉字会被转换成乱码。在CLR对应ASCIIEndoing。

    UTF-16     每个字符编码成2个字节,它不会对字符产生任何影响,也不会涉及到压缩处理,性能非常好,因为CLR中的字符也是16位的Unicode。在CLR中对应UnicodeEncoding。

    UTF-32     使用4个字节编码成一个字符。从内存角度上讲,它并不是一种高效能的编码方案,因为第个字符都是4个字节,特别占内存,所以很少用来做文件和网络流的编码解码。在CLR中对应UTF32Encoding。

    UTF-8      值在Ox0080之下的字符压缩成一个字符,也就是ASCII码;值在0X0080---0X07FF之间的字符都转换成2个字符,适合用于欧洲和中东地区。0X0800以上被转换成3个字符,适合于东亚地区的字符。代理项被转换成4个字节。因此,它是一种非常流行的编码,适用于互联网。它在处理0X0800以上的字符效率不好UTF-16。在CLR中对应UTF8Encoding。

    UTF-7     这咱编码通常用于旧的系统,那时的系统是用7位值表示。目前已经被Unicode协淘汰。在CLR中对应UTF7Encoding。


————————————————









原文转载:http://www.shaoqun.com/a/804606.html

跨境电商:https://www.ikjzd.com/

飞书互动:https://www.ikjzd.com/w/1319.html

tracker:https://www.ikjzd.com/w/2720

livingsocial:https://www.ikjzd.com/w/714.html

汇通天下:https://www.ikjzd.com/w/2055


publicIActionResultGetHiPda(){cookies=@"__utmz=128828693.1622702936.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);cdb_cookietime=2592000;cdb_auth=fd05ACWP2GIZl8k0oqBaZUtQ8WjXIxIXESeqpdSfAzikX
急速:https://www.ikjzd.com/w/1861
cicpa考试:https://www.ikjzd.com/w/1375
i号店:https://www.ikjzd.com/w/2263
山村韵事口述我的姐夫竟然是我一夜情的野男人:http://lady.shaoqun.com/m/a/273945.html
17岁女儿竟当我的面和男友做爱:http://lady.shaoqun.com/m/a/273161.html
纠结:我爱上了已婚的装修工:http://lady.shaoqun.com/a/272979.html
什么样的女人配不上男人?恋人用五种"心理操纵"来抓住你的丈夫:http://lady.shaoqun.com/a/375192.html
女人在生理上得不到"满足",出去"出轨"是一种习惯,说"需求大":http://www.30bags.com/a/392402.html
订单有望?传美国新发钱计划将从7月起持续到年底!:https://www.ikjzd.com/articles/145758


That's the article: .net6环境下RestSharp获取gbk网页乱码的解决方案
Thank you for visiting my blog, hopefully it can be useful for all of you. Don't forget to share this article with your friends so they also know the interesting info, see you in other article posts.

You are now reading the article .net6环境下RestSharp获取gbk网页乱码的解决方案 with link address https://socialnetworkingupdate.blogspot.com/2021/06/net6restsharpgbk.html

More Articles

Post a Comment

Mas Bago Mas luma

Iklan In-Feed (homepage)

#Advertisement