简体   繁体   中英

Include post variables in a createDocumentFromUrl call in .NET

I have a project in Visual Basic 2010 Express that parses web pages use the IHTMLDocument object. Here is the function I am using to retrieve a web page:

Private Function GetHTML(ByVal url As String)
    Dim htmldoc As New HTMLDocument()
    Dim ihtml2 As IHTMLDocument2
    Dim ihtml3 As IHTMLDocument3
    Dim iPersistStream As IPersistStreamInit

    iPersistStream = DirectCast(htmldoc, IPersistStreamInit)
    iPersistStream.InitNew()

    ihtml2 = htmldoc.createDocumentFromUrl(url, vbNullString)

    Do Until ihtml2.readyState = "complete"
        'required for htmlresult.readyState to transition from "loading" to "complete"
        System.Windows.Forms.Application.DoEvents()
    Loop
    ihtml3 = DirectCast(ihtml2, IHTMLDocument3)

    Return ihtml3
End Function

I'm basically doing stuff like this with the function:

ihtml = GetHTML("www.blah.com?getvar1=x&getvar2=y")
ihtml.getElementsByTagName("A")
ihtml.getElementById("myel")
etc, etc...

I'm trying to figure out how I can include POST variables in addition to the URL string when I retrieve the HTML document. By which I mean I'd like to be able to something like this:

ihtml = GetHTML("www.blah.com?getvar1=x&getvar2=y",["postvar1=a","postvar2=b"])

So I'd like to modify my existing GetHTML function in order to allow me to include post variables if that is possible and if not I'd like to know if there is perhaps another way to do this. Thanks to anyone who can help.

Ok, I would have used WebCilent or WebRequest but... if you're committed to this design:

You have to navigate to the page, find each input field, set the value then call InvokeMember on the button for that page. WebBrowser is all about automating a web browser, not so much about making HTTP requests programatically.

Sample code: http://muftisubzero.blogspot.com/2010/12/playing-with-webbrowser-class-cnet.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM