简体   繁体   中英

Visual Basic 2010 Html Form

Im getting used to Visual Basic currently and im trying to build an application that our operators can submit quick searches to one of our systems. - I have looked around for this and I couldnt find a lot of information

Below is a quick overview on what we would like to achieve somehow

1. VB 2010 App (2 x Text Boxes + Button) 
2. PHP Script (If query = bob & jones <<=
3. Curl PHP Request to another PHP Form
4. Returns to Original PHP Script <<= 
5. Somehow returns information back to .net application that is waiting

I am a PHP Programmer rather than a .net developer mainly so the curl and php scripts are mostly complete its just the .net coding

To get us started we used the following code :

    Dim webStream As Stream

    Dim webResponse = ""

    Dim req As HttpWebRequest

    Dim res As HttpWebResponse

    ' API Address ''

    req = WebRequest.Create("xxxxxxxxx")



    req.Method = "GET" ' Method of sending HTTP Request(GET/POST)

    res = req.GetResponse() ' Send Request



    webStream = res.GetResponseStream() ' Get Response

    Dim webStreamReader As New StreamReader(webStream)

    ' READ Response in one Variable

    While webStreamReader.Peek >= 0

        webResponse = webStreamReader.ReadToEnd()

    End While
    MsgBox(webResponse)

It was working fine to one standard because it was bringing the information back to us in the form of a messagebox , albeit we wanted it to populate a few text boxes (Not even sure if that is possible)

But the main problem was that it was retrieving the source code of the website instead of just information on the text side of the website

Thanks

You seem to have this part way completed already. you have the markup, just dig into it.

Here is an alternate way of writing your code above.

Dim MyURL as string = "xxxxxxx"
Dim MyRequest As WebRequest = WebRequest.create(MyURL)
MyRequest.Headers.Add("myCustom","true") 'PHP Web Server @ xxxxxxx will see this as $_SERVER['http_myCustom'] - true
MyRequest.ContentType = "text/html"
MyRequest.Method = "GET"

Dim MyResponse As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

If MyResponse.StatusCode = HttpStatusCode.OK Then
    Dim SR As New StreamReader(MyRequest.GetResponseStream())
    MyRequest.Close()
    Dim webResponse As String = SR.ReadToEnd()
    SR.Close()

    'At this point, the source of the page is in webResponse

Else
    MyRequest.Close()
    'Error in connection to remote/host server
End If

I added the Header to the request to show that you could simply check for the existence of this header, and/or the referrer, on the external site to handle the response by that site differently.. that is, if you don't want to parse the entire source in webRequest, than you should consider not sending an entire document from the external site.

For, I assume you're just interested in getting search results that are parsed to text/html by the external server.

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