vb.net HttpWebRequest无法检索数据?

时间:2018-07-28 15:15:45

标签: httpwebrequest

我正在制作一个小应用程序,用于从各种网站上检索马的血统书和比赛信息,并将其汇总成马的历史摘要。但是,我在解决为什么以下代码Keep返回网站主页而不是搜索页面的过程时遇到了麻烦。

Iv一遍又一遍地看网页html,我不能缝找出原因。 n.b编程对我来说还很新,所以我可能会错过明显的东西...

感谢您提供的任何帮助。...

    Dim url As String = "http://www.pedigreequery.com/cgi-bin/new/check2.cgi"
    Dim req = CType(WebRequest.Create(url), HttpWebRequest)
    Dim postData = "query_type=check&search_bar=horse&h=" & "Officer Drivel" & "&g=5&inbred=Standard&x2=n"
    Dim data = Encoding.ASCII.GetBytes(postData)

    req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8;charset=utf-8"
    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded;charset=utf-8"
    req.ContentLength = data.Length

    Using stream = req.GetRequestStream()
        stream.Write(data, 0, data.Length)
    End Using

    Dim result = CType(req.GetResponse(), HttpWebResponse)
    Dim receiveStream = result.GetResponseStream()

    If receiveStream IsNot Nothing Then
        MsgBox("receiveStream is not nothing")

        Dim reader = New StreamReader(receiveStream, Encoding.ASCII)
        Dim respHtml = reader.ReadToEnd()

        File.WriteAllText(Directory.GetCurrentDirectory() & "/resphtml.txt", respHtml)

        Dim htmlDoc = New HtmlDocument()
        htmlDoc.LoadHtml(respHtml)
        TextBox1.Text = respHtml

0 个答案:

没有答案