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

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题