PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Interfacing to a website? Need general guidance. [RESOLVED]-VBForums
Results 1 to 11 of 11

Thread: Interfacing to a website? Need general guidance. [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Interfacing to a website? Need general guidance. [RESOLVED]

    I need to interface to a website.

    One of our suppliers runs an on-line help desk. (We have no control over that code.)

    I need to log-on, post data, read data etc. automatically from within our own local VB6 on MS Access help desk.

    In short, I need to drive a browser in some automated fashion, with my code pressing buttons, entering/reading data etc.

    So far I can get the log-in screen into the WebBrowser control and can see the raw HTML via its document property.

    I know I now need to send a log-on string somehow, but I'm a bit lost. Can I do that via the WebBrowser, or do I need a Winsock? How do I determine what string to send? Trapping the data coming out of the WebBrowser control (when manually operated) should presumably show me what is needed, but how do I do that?

    Am I on the right track? Is the WebBrowser control the best way to do this?

    Any guidance much appreciated.
    Last edited by BrianHawley; Jan 3rd, 2004 at 03:43 AM.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Hi Brian,

    In situation like yours, i would use the Inet control. Its pretty easy to use.
    e. g.

    VB Code:
    1. Dim x() As Byte
    2.     Dim txt As String
    3.     Dim URL As String
    4.    
    5.     URL = "http://www.vbforums.com/"
    6.    
    7.     x() = Inet1.OpenURL(URL, 1)
    8.    
    9.     txt = ""
    10.    
    11.    
    12.     Dim N As Integer
    13.    
    14.     For N = 0 To UBound(x)
    15.         txt = txt + Chr(x(N))
    16.     Next
    17.  
    18.    MsgBox txt

    WebBrowser control would let you view the page, but i doubt you would need that. You can simply use Post, Get method to perform the tasks and exatract and process the response returned pretty easily like the above example. Apart from the OpenUrl method you can also use Execute aswell.

    Hope this helps.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,705
    If your supplier is very client oriented, you could suggest to their IT guy to expose a webservice which can retrieve that information. (they may even already have one online you don't know about it!)

  4. #4

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    Thanks guys, but my need is a bit more complex than that.

    I'm using the WebBrowser control and making some progress.
    VB Code:
    1. Private Sub Command1_Click()
    2.     'Loads the page
    3.     txtStatus = "Busy"
    4.     WB.Navigate "http://www.domain.com/logon.asp"
    5.     Do While WB.ReadyState <> READYSTATE_COMPLETE
    6.         DoEvents
    7.     Loop
    8.  
    9.     txtStatus = "Done"
    10. End Sub
    11.  
    12. Private Sub Command2_Click()
    13.     'Log on
    14.     WB.Document.????? 'Need something here to fill in the name and password
    15.     WB.Document.Forms(0).Login.Click 'Clicks the log in button
    16. End Sub
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  5. #5
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Use Winsock with HTTP Headers something like this....
    VB Code:
    1. Private Sub Command1_Click()
    2.   Winsock1.Connect "www.domain.com", 80
    3. End Sub
    4.  
    5. Private Sub Winsock1_Connect
    6. Dim Header$
    7. Dim PostData$
    8.  
    9.    PostData = "Username=Johnny&Password=12deadkittens"
    10.  
    11.    Header = "POST http://www.domain.com/logon.asp" & VbCrLf _
    12.                 & "Host: www.domain.com" & VbCrLf _
    13.                 & "Content-Length: " & Len(PostData) & vbCrlf & vbCrLf
    14.  
    15.         Winsock1.SendData Header & PostData & VbCrLf & VbCrLf
    16. End Sub
    Rough example, you would need to trace all the headers sent by your browser while logging in and getting the data you want, then just mimmick it.

  6. #6
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by BrianHawley
    Thanks guys, but my need is a bit more complex than that.
    It was merely an example, i have used Inet control to interface with member only websites and extract data. Personally i dont think web browser control is the way to go. Inet control or WinSock (as Spajeoly suggested) would be more appropriate.

    But if you feel comfortable with WebBrowser control then go with that.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  7. #7
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,344

    Well ...

    In my opinion the best course of action would be to set up a connection to the remote database, which your VB app could use to directly update data into the online database. Somehow I don't like the idea to use the same web interface through your software. Or maybe you could write a component to do that and call the component remotely.

    Using the web interface would be too shaky in my opinion, as a simple fieldname change, or a change of an ASP page on the server could force you to rewrite your code. Also in case there are any errors along the path you won't come to know of them decently.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  8. #8
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    HB, i agree with you totally. Unfortunately a very few company will let you access their database directly. I usually get them to write some API and use those API to access the database.

    This is the best way as the client/supplier dont have to worry about me messing up their database and viewing information they dont want me to view. The API will only let me retrive the data i need.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  9. #9
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Well, you can use the WebBrowser control to dynamically fill in the page and press buttons and such... Use the Document Object Model for that; you can find much info on that at MSDN.
    VB Code:
    1. Private Sub Command1_Click()
    2.     'Loads the page
    3.     txtStatus = "Busy"
    4.     WB.Navigate "http://www.domain.com/logon.asp"
    5.     Do While WB.ReadyState <> READYSTATE_COMPLETE
    6.         DoEvents
    7.     Loop
    8.  
    9.     txtStatus = "Done"
    10. End Sub
    11.  
    12. Private Sub Command2_Click()
    13.     'Log on
    14.     WB.Document.getElementById("txtLoginName").value = "Username"
    15.     WB.Document.getElementById("txtPassword").value = "Password"
    16.     WB.Document.Forms(0).Login.Click 'Clicks the log in button
    17. End Sub
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  10. #10
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,344
    Originally posted by Danial
    HB, i agree with you totally. Unfortunately a very few company will let you access their database directly. I usually get them to write some API and use those API to access the database.

    This is the best way as the client/supplier dont have to worry about me messing up their database and viewing information they dont want me to view. The API will only let me retrive the data i need.
    The whole problem with automating a webpage interaction is it would become too difficult to maintain in case the website design changed even slightly.

    An alternative way we had followed in our last project was to use a text file with SQL INSERT and UPDATE queries, and upload it onto the website and then invoke a pre-determined ASP page which would process this file. Even this approach would work much better than filling up fields on a webpage. You could throw in the SSL and other security checks to ensure nobody sniffs the text file being transferred, and at least the file transfer mechanism would give you proper error details in case anything failed. After that you would be interacting with just one ASP page, which would just have to execute the SQL statements inside the text file, so that's a whole deal less hassles than having to wade through numerous fields on a webpage, finding and 'clicking' the submit button and then tracking the errors etc.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  11. #11

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    Since we have no access other than via the webpage, we cannot set up a direct SQL connection.

    We have gone with the WebBrowser control to dynamically fill fields, press buttons etc. as it is quick and simple. It's working very well.

    I take the point about the website changing, so we verify its layout every time. I doubt it's going to change frequently, and it is an easy fix if it does.

    Thanks guys.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width