Click to See Complete Forum and Search --> : Cgi-Bin and Winsock
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.
privoli
May 15th, 2000, 12:40 PM
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
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?
privoli
May 16th, 2000, 09:19 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.