AAOOOOOAA 2016-05-02 06:05 采纳率: 0%
浏览 849
已结题

关于vb.net的post get问题 404错误

Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Web

Imports System.Net.Security
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates

Public Class Form1

Private Shared Function CheckValidationResult(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal errors As SslPolicyErrors) As Boolean
    Return True '总是接受  
End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim httpQonse As System.Net.HttpWebRequest  '发送类
    Dim httpPonse As System.Net.HttpWebResponse '返回类
    Dim httpURL As String = "https://www.zhihu.com/question/44423380" '请求链接
    '-----------------------------------------------------声名各种变量
    httpQonse = CType(Net.HttpWebRequest.Create(httpURL), Net.HttpWebRequest)
    httpQonse.Method = "GET"           '请求方法

    httpQonse.ProtocolVersion = HttpVersion.Version10
    ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf CheckValidationResult)

    httpQonse.KeepAlive = True         '建立非持久连接
    httpQonse.AllowAutoRedirect = True '允许重定向
    httpQonse.Timeout = 60000          '超时时间
    httpQonse.UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" '设置浏览器版本
    '-----------------------------------------------------整理各种变量
    MsgBox(httpQonse.GetResponse.Headers)
    httpPonse = CType(httpQonse.GetResponse(), Net.HttpWebResponse)
    Dim resStream As Stream = httpPonse.GetResponseStream()
    '-----------------------------------------------------获取数据流
    Dim List As New List(Of Byte)
    Dim n As Integer
    n = resStream.ReadByte()
    Do Until n = -1
        List.Add(n)
        n = resStream.ReadByte()
    Loop
    Dim mybyte() As Byte
    mybyte = List.ToArray
    '-----------------------------------------------------数据流转字节组数
    TextBox1.Text = System.Text.Encoding.GetEncoding("utf-8").GetString(mybyte) '返回html(mybyte为字节数组)
    TextBox2.Text = httpPonse.Headers.ToString                                  '返回所有协议头

    httpPonse.Close()                           '关闭响应流
End Sub

End Class


图片说明

怎么破,获取不到404页面的HTML代码。。。求高人指点。。。(话说 vb6上面的winhttp获取没问题)

  • 写回答

1条回答

  • threenewbee 2016-05-02 15:43
    关注

    url地址错误
    https://www.zhihu.com/question/44423380
    你在浏览器里输入下就知道了,它本来就是404

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码