WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Examples

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Send a GET or a POST request to a CGI server

Keywords:     HTTPRecvQuery    @HMethodPost   @HMethodGet

;**************************************************************************
;		  WEB FORM CGI CLIENT SAMPLE WINSOCK APP
;
; This script sends a GET or a POST request to a CGI server.
;
; Author: Jennifer Palonus (GDI)
; 
;  Date	   Major changes
; -------  ----------------------------------------------------------------
; 30apr96  Created.
;**************************************************************************
sTitle	   = "TestCGI"
sViewer	   = "Viewer"
sDial	   = "%param1%"


AddExtender ("wwwsk34I.dll")


;Dial our host, asking first if user has more than 1 defined...
hConn = 0
sDialUps = DUNItemize ()
if (ItemCount(sDialUps,@TAB) == 1)
	sDial = sDialUps
else
	sDial = AskItemList ("Choose a dial-up connection", sDialUps, @TAB, @SORTED, @SINGLE)
endif

hConn = DUNConnect (sDial)
nErr = wxGetLastErr()
if (!hConn)
	select (nErr)
		case @SErrBusy
			Message (sTitle, "Couldn't connect to %sDial%: Line busy.")
			break
		case @SErrNoAnswer
			Message (sTitle, "Couldn't connect to %sDial%: No answer.")
			break
		case @SErrVoice
			Message (sTitle, "Couldn't connect to %sDial%: A human answered.")
			break
		case nErr
			Message (sTitle, "Couldn't connect to %sDial%: Error %nErr%.")
	end select
	exit
endif


; This is our "browser"...
if (!WinExist (sViewer))
	Run ("notepad.exe","%sViewer%.")
	if (WinExistChild("Notepad", "Cannot find the %sViewer%"))
		SendKeysChild ("Notepad", "Cannot find the %sViewer%", "~")
	endif
	WinTitle ("%sViewer% - Notepad", sViewer)
	SendKeysTo (sViewer, "!ew") ; Turn on word-wrap
else
	; Clear the existing browser window...
	SendKeysTo (sViewer, "!ea{del}")
endif
SendKeysTo (sViewer, "---------------------------------------~")


nDlgRet = 1
while (nDlgRet <> 2)
	; Get the form data...
	dlgTestCGIFormat=`WWWDLGED,5.0`
	dlgTestCGICaption=`TestCGI`
	dlgTestCGIX=59
	dlgTestCGIY=70
	dlgTestCGIWidth=262
	dlgTestCGIHeight=135
	dlgTestCGINumControls=17
	dlgTestCGI01=`8,6,44,DEFAULT,STATICTEXT,DEFAULT,"Server:"`
	dlgTestCGI02=`8,18,44,DEFAULT,STATICTEXT,DEFAULT,"CGI path:"`
	dlgTestCGI03=`52,6,106,DEFAULT,EDITBOX,edServer,""`
	dlgTestCGI04=`52,18,106,DEFAULT,EDITBOX,edCGIPath,""`
	dlgTestCGI05=`176,18,36,DEFAULT,RADIOBUTTON,rbMethod,"POST",1`
	dlgTestCGI06=`176,6,36,DEFAULT,RADIOBUTTON,rbMethod,"GET",2`
	dlgTestCGI07=`32,36,108,DEFAULT,STATICTEXT,DEFAULT,"Name         =          Value"`
	dlgTestCGI08=`8,48,64,DEFAULT,EDITBOX,edName1,""`
	dlgTestCGI09=`72,48,182,DEFAULT,EDITBOX,edValue1,""`
	dlgTestCGI10=`8,64,64,DEFAULT,EDITBOX,edName2,""`
	dlgTestCGI11=`72,64,182,DEFAULT,EDITBOX,edValue2,""`
	dlgTestCGI12=`8,80,64,DEFAULT,EDITBOX,edName3,""`
	dlgTestCGI13=`72,96,182,DEFAULT,EDITBOX,edValue4,""`
	dlgTestCGI14=`8,96,64,DEFAULT,EDITBOX,edName4,""`
	dlgTestCGI15=`72,80,182,DEFAULT,EDITBOX,edValue3,""`
	dlgTestCGI16=`62,116,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Submit",1`
	dlgTestCGI17=`132,116,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",2`
	
	nDlgRet=Dialog("dlgTestCGI")
	if (nDlgRet == 2)
		break
	endif

	if (rbMethod == 1)
		rbMethod = @HMethodPost
	else
		rbMethod = @HMethodGet
	endif


	; Build the CGI query string...
	sQuery = ""
	for n = 1 to 4
		if (edName%n% <> "")
			sQuery = strcat (sQuery, "&", edName%n%, "=", URLEncode(edValue%n%))
		endif
	next n
	if (strindex (sQuery, "&", 1, @FWDSCAN)==1)
		sQuery = strsub (sQuery, 2, strlen(sQuery)-1)
	endif


	; Post the CGI query...
	sPage = HTTPRecvQuery (edServer, edCGIPath, sQuery, 32767, rbMethod)
	nErr = wxGetLastErr()
	if (nErr <> @SOK)
		Message (sTitle, "Error receiving web page: %nErr%")
	endif


	ClipPut (sPage)
	SendKeysTo (sViewer, "^v~")
	SendKeysTo (sViewer, "---------------------------------------~")
endwhile


; User hit Cancel...
:Cancel

; Hang up...
:HangUp
if (hConn)
	nRet = DUNDisconnect (hConn)
endif

exit




Article ID:   W12638
Filename:   Send a GET or POST Request to CGI Server.txt
File Created: 2001:03:01:15:12:00
Last Updated: 2001:03:01:15:12:00