绕过 308 永久重定向

问题描述

我正在尝试从带有一些 vb .net 代码的 URL 下载内容

Dim httpclienthandler = New httpclienthandler
With httpclienthandler
    .AllowAutoRedirect = True
End With
Using request = New HttpRequestMessage(HttpMethod.[Get],New Uri(url))
    request.Headers.TryAddWithoutValidation("Accept","text/html,application/xhtml+xml,application/xml")
    request.Headers.TryAddWithoutValidation("Accept-Encoding","gzip,deflate")
    request.Headers.TryAddWithoutValidation("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/76.0.3809.132 Safari/537.36")
    request.Headers.TryAddWithoutValidation("connection","keep-alive")
    request.Headers.TryAddWithoutValidation("Accept-Charset","ISO-8859-1")
    Dim httpClient = New HttpClient(httpclienthandler)
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls

    Using response = Await httpClient.SendAsync(request).ConfigureAwait(False)
        response.EnsureSuccessstatusCode()

        Using responseStream = Await response.Content.ReadAsstreamAsync().ConfigureAwait(False)

            Using decompressedStream = New GZipStream(responseStream,CompressionMode.Decompress)

                Using streamReader = New StreamReader(decompressedStream)
                    Return Await streamReader.ReadToEndAsync().ConfigureAwait(False)
                End Using
            End Using
        End Using
    End Using
End Using

从最近开始,这开始返回 308 - 永久重定向。我尝试过的一件事是添加 .AllowAutoRedirect,但它没有帮助。此外,我已经看到一些答案,建议尝试 ping 响应的 Location 标头中的 URL,但在我的情况下,位置标头与我首先尝试 ping 的 URL 相同,因此它是一个循环。

有没有办法绕过 308 重定向并以某种方式获取内容?在浏览器中,URL 按预期正常工作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...