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

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?