Results 1 to 4 of 4

Thread: Cgi-Bin and Winsock

  1. #1
    Guest

    Red face

    I can use winsock to connect to this website, but need to know how to send info to its cgi bin and then have what it sends back be displayed in a text box. It needs to connect to 'www.m-w.com' and the cgi it need to use is at '/cgi-bin/dictionary' It looks up words in a dictionary by putting '?theword' at the end of the cgi part i just mentioned. If anyone has an idea on how to do this i would appreciate it, thanks.

  2. #2
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126
    If you have any problems with this let me know!
    Create a new form...

    Add a text box caled "Text1"
    Add a command button called "Command1"
    Add a winsock control called "Winsock1"

    Set Text1 to MultiLine = True and ScrollBars = Both

    Private Sub Command1_Clik()
    'connect to server
    Winsock1.connect "www.m-w.com", 80
    End Sub

    Private Sub Winsock1_Connect()
    'send http request (ask for the file)
    Winsock1.senddata "POST /cgi-bin/dictionary?theword HTTP/1.0" & vbclrf & vbcrlf
    End Sub

    Private Sub Winsock1_DataArrival(bytes as long)
    'weve recieved a packet, keep track of it and add it to the text box
    Winsock1.getdata TempStr, vbString
    text1.text = text1.text & TempStr
    End Sub

    Private Sub Winsock1_Close()
    'its complete, the httpd server automatically closes the connection
    msgbox "CGI post complete."
    End Sub
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

  3. #3
    Guest
    That code worked fine, but all the server sends back is this:

    HTTP/1.1 200 OK
    Date: Tue, 16 May 2000 05:58:11 GMT
    Server: Apache/1.3.6 (Unix)
    Connection: close
    Content-Type: text/html

    And thats it, any ideas?

  4. #4
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126
    It's doing that due to the CGI post not correctly setup... Try using GET method instead of POST...

    Const WordStr as String = "Digital"

    Private Sub Command1_Clik()
    'connect to server
    Winsock1.connect "www.m-w.com", 80
    End Sub

    Private Sub Winsock1_Connect()
    'send http request (ask for the file)
    Winsock1.senddata "GET /cgi-bin/dictionary?" & WordStr & " HTTP/1.0" & vbclrf & vbcrlf
    End Sub

    Private Sub Winsock1_DataArrival(bytes as long)
    'weve recieved a packet, keep track of it and add it to the text box
    Winsock1.getdata TempStr, vbString
    text1.text = text1.text & TempStr
    End Sub

    Private Sub Winsock1_Close()
    'its complete, the httpd server automatically closes the connection
    msgbox "CGI post complete."
    End Sub
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

Posting Permissions

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



Click Here to Expand Forum to Full Width