c#,Http请求返回未知字符

本文关键字:未知 字符 返回 请求 Http | 更新日期: 2023-09-27 18:20:04

我有这个代码


internal static SourceCookieSTatue LoadSource(string p)
{
    SourceCookieSTatue __Result__ = new SourceCookieSTatue();
    try
    {
        var Request = (HttpWebRequest)WebRequest.Create(p.Trim());
        Request.UserAgent = MrHTTP.Chrome_UserAgent;
        Request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        Request.Headers.Add("Accept-Language", "en-US,en;q=0.5");
        Request.Headers.Add("Accept-Encoding", "gzip, deflate");
        var response = (HttpWebResponse)Request.GetResponse();
        string x = new StreamReader(response.GetResponseStream()).ReadToEnd();
        string CokString = MrHTTP.GetCookieString(response.Headers);
        return new SourceCookieSTatue(x, CokString);
    }
    catch (Exception sa) { return new SourceCookieSTatue(sa.Message,false);   
}

当我发送http请求时,它会返回类似以下的字符

���;Yo#Gz���⑪�d7��(QcIsz5�K�d1���d���z��"5Z�十、�一��!oA o��Yl ��WH��� ����>8#ً���������{����4.㞋??8zp���一�M��0个�F{�����结核病?��2.��q�i3΃�a、 }��Y85��K�+&'�m���mnk{k�r����ѸLw;�

当我使用BURP SUite拦截请求时,它工作正常。

c#,Http请求返回未知字符

问题出现在以下行:

            Request.Headers.Add("Accept-Encoding", "gzip, deflate");

您正在请求标头中添加一个压缩参数。您可以删除压缩参数,也可以通过添加以下行来定义解压缩请求的默认行为:

            Request.AutomaticDecompression = DecompressionMethods.GZip;