Or encoding, HttpWebRequest

Source: Internet
Author: User

When using HttpWebRequest to capture information, for example, Baidu's information,

The Code is as follows:

String url = string. Format ("http://www.baidu.com/s? Wd = {0} ", HttpUtility. UrlEncode (" computer "));

 

At this time, the default encoding format is UTF8, And the request sent to the browser is:

Http://www.baidu.com? Wd = % e5 % a4 % a9 % e6 % 9% c % ba

If you use

String url = string. Format ("http://www.baidu.com/s? Wd = {0} ", HttpUtility. UrlEncode (" computer ", Encoding. Default ));

The current encoding format is generally GB2312, so the request sent to the browser is:

Http://www.baidu.com? Wd = % cc % ec % bb % fa

The display content of these two requests is different. Because Baidu adopts the gb2312 encoding format, the correct result can be obtained only in the latter method.

Therefore, when making such a captured request, the requested data must be consistent with the server's encoding format. Otherwise, the correct data cannot be returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.