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.