.Net HttpWebRequest 响应返回一些疯狂的字符

.Net HttpWebRequest Response Returning Some crazy characters

当我使用此代码发送 GET 时:

Private Function SendGet(ByVal URL As String, ByRef CookieJar As CookieContainer, ByVal Method As String)
    Dim reader As StreamReader
    Dim responseString As String = ""
    Try

        Dim Request As HttpWebRequest = HttpWebRequest.Create(URL)
        Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"
        Request.CookieContainer = CookieJar
        Request.AllowAutoRedirect = False
        Request.Accept = "application/json, text/javascript, */*; q=0.01"
        Request.Headers.Add("Accept-encoding", "gzip, deflate")
        Request.Headers.Add("Accept-Language", "en-US,en;q=0.5")
        Request.CookieContainer = CookieJar
        Request.Host = "Removed"
        Request.Referer = "https://www.removed.com"
        Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"
        Request.Headers.Add("X-Requested-With", "XMLHttpRequest")
        Dim Response As HttpWebResponse = Request.GetResponse()

        For Each tempCookie In Response.Cookies
            CookieJar.Add(tempCookie)
        Next

        reader = New StreamReader(Response.GetResponseStream())
        responseString = reader.ReadToEnd()
        Response.Close()

    Catch ex As Exception
        MsgBox(ex.Message.ToString)
    End Try

我发送的 headers 与我的浏览器发送的相同。我也(以前)通过 POST 登录(不同的功能)来获取一个 cookie,所以我发送的 cookie 容器确实包含一个有效的 cookie,我也已经确认了这一点。

我在浏览器开发工具中看到的响应很干净 JSON,但是代码 returns 太疯狂了:(我已经削减了大约 90% 的内容)。 这是我出了什么问题还是有什么方法可以解密这个?

�      �X�o�8�W�<�S�KJ�з���=���mo���Lb��9:��~��B    W*�[�:�}����_gJ�%M�3���kx���3�u���O�?4'72�c:��3�L�4΅,�p�Le���9䆳ܹ���u4

免责声明:我有权自动执行此过程

该流看起来像是您正在从服务器获取压缩数据。那是因为你在传递 "accept-encoding" 时指定了 gzip(例如 - 告诉服务器 "send me compressed data if you support gzip")。

因此,要么放弃您的 "accept-encoding" header,要么对返回的字节实施快速 gzip 解压缩。在 vb.net.

中已经有 another stack article 向您展示如何做到这一点