.Net HttpWebRequest响应返回一些疯狂的角色

时间:2016-01-07 12:01:55

标签: vb.net httpwebrequest httpwebresponse

当我使用此代码发送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

我发送的标题与我的浏览器发送的标题相同。我也(以前)通过POST登录(不同的功能)来获取cookie,因此我发送的cookie容器确实包含我已经确认的有效cookie。

我在浏览器开发人员工具中看到的响应是干净利落的JSON,但是代码又回归了这种疯狂:(我已经减少了90%左右的fyi)。 这是我出错了还是有办法解密这个?

�      �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

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

1 个答案:

答案 0 :(得分:1)

该流看起来像是从服务器获取压缩数据。那是因为你通过指定的gzip传递“accept-encoding”(例如 - 如果你支持gzip,告诉服务器“发送压缩数据”)。

因此,要么丢弃“accept-encoding”标头,要么对返回的字节实施快速gzip解压缩。已经another stack article向您展示了如何在vb.net中执行此操作。