Hello John,
thank you very much to share the source from Norbert and Bob.
That one from Bob I could not to get running. But that from Norbert
works well. I changed it a little bit to make it working with my perl
script which is on the internet server. I use it with VO27. Here I share
the updated code:
FUNCTION sendDataByPostToCgi(cServer,cCgiPath,cPostData,cError)
/*
Die Funktion sendet Daten an ein CGI-Script.
Beispiel:
LOCAL cServer,cCgiPath,cPostData,cError AS STRING
cServer := "
www.killetsoft.de"
cCgiPath := "cgi-bin/xxxxxxxx/
xxxxxxx.pl"
cPostData := "field1=value1&field2=value2&field3=value3"
if .not. sendDataByPostToCgi(cServer,cCgiPath,cPostData,@cError)
? cError
else
? "Daten erfolgreich übertragen"
endif
*/
// Variablen
LOCAL cHeader AS STRING
LOCAL lResult AS LOGIC
LOCAL oHttp AS cHttp
// Parameter aufbereiten
oHttp := cHttp{"KilletSoft"}
IF .not. Left(cCgiPath,1) == "/"
cCgiPath := "/" + cCgiPath
ENDIF
// Header vorbelegen
cHeader := "Accept: *" + "/" + "*" + CRLF
cHeader += "Man: POSThttp://" + cServer + cCgiPath + " HTTP/1.1" + CRLF
cHeader += "Content-Type: text/html; charset=utf-8" + CRLF
// Daten senden. Methode POST, Timeout 200 Millisekunden
lResult :=
oHttp:GetDocumentByGetOrPost(cServer,cCgiPath,cPostData,cHeader,"POST",200)
// Fehlermeldung zurück geben
IF .not. lResult
IF .not. IsNil(cError)
cError := oHttp:PostErrorMsg
ENDIF
ENDIF
// Aufräumen
oHttp:CloseRemote()
oHttp:Axit()
RETURN lResult
METHOD
GetDocumentByGetOrPost(cServer,cDocument,cData,cHeader,cMethod,nTimeOut,nPort,nFlags)
CLASS cHttp
/******************************************************************
GET or POST - that's the question
Norbert Kolb, 11/17/03, 12/02/04, 09/02/04 02/25/05
UG Bodensee (A, CH, D, FL)
Fred Killet, 03/29/19
Killet Software Ing.-GbR
*******************************************************************
First the InternetOpen FUNCTION IS called TO initialize the
remaining functions. Then the InternetConnect FUNCTION IS called
TO identify the type OF service being requested. THIS IS necessary
AS the same set OF functions can be used TO interact WITH a number
OF different servers.
/*****************************************************************/
// Varialblen
LOCAL lResult AS LOGIC
LOCAL lRet AS LOGIC
LOCAL nSecur,nLen AS DWORD
// Default-Parameter
Default(@cDocument,"")
Default(@cData,"")
Default(@cMethod,"GET")
Default(@nPort,SELF:nPort)
Default(@nFlags,0)
Default(@nTimeOut,1000)
// Vorbelegungen
lRet := FALSE
SELF:PostErrorMsg := ""
// HTTPS-Port ermitteln
IF _AND(DWORD(nFlags),INTERNET_FLAG_SECURE) = INTERNET_FLAG_SECURE
nPort := INTERNET_DEFAULT_HTTPS_PORT
SELF:nPort := nPort
ENDIF
// Use opened session or open new http session.
IF SELF:hSession == NULL_PTR
lResult := SELF:Open(NIL,SELF:cProxy)
ELSE
lResult := TRUE
ENDIF
// Identify the type of service that is being accessed
IF lResult
IF SELF:hConnect == NULL_PTR .or. SELF:cHostAddress <> cServer
SELF:cHostAddress := cServer
SELF:hConnect := InternetConnect(;
SELF:hSession,;
String2Psz(SELF:cHostAddress),;
nPort,;
String2Psz(SELF:cUserName),;
String2Psz(SELF:cPassword),;
INTERNET_SERVICE_HTTP,;
nFlags,;
0;
)
ENDIF
// Once we've identified the service, we need to indicate the
// page to which the data will be posted.
IF SELF:hConnect <> NULL_PTR
SELF:__SetStatusObject()
SELF:hRequest := HttpOpenRequest(;
SELF:hConnect,; // hConnect
String2Psz(cMethod),; // lpszVerb
String2Psz(cDocument),; // pszObjectName
String2Psz("HTTP/1.1"),; // pszVersion
NULL_PSZ,; // pszReferer
NULL_PSZ,; // pszAcceptTypes
nFlags,; // dwFlags
SELF:__GetStatusContext(); // dwContext
)
// We need to add a header to notify the web server that the
// incoming data is form encoded and then send the request.
IF SELF:hRequest <> NULL_PTR
SELF:__SetStatus(SELF:hRequest)
IF cMethod == "POST"
IF Empty(cHeader)
cHeader := "Content-Type: application/x-www-form-urlencoded"
+ CRLF + HEADER_ACCEPT
ENDIF
ELSE
IF Empty(cHeader)
cHeader := HEADER_ACCEPT
ENDIF
ENDIF
// Connect requested headers
IF
HttpAddRequestHeaders(SELF:hRequest,String2Psz(cHeader),SLen(cHeader),HTTP_ADDREQ_FLAG_ADD)
// Sometimes you have to set SECURITY_FLAGS
nLen := _sizeof(DWORD)
InternetQueryOption(SELF:hRequest,INTERNET_OPTION_SECURITY_FLAGS,@nSecur,@nLen)
nSecur := _OR(nSecur,SECURITY_FLAG_IGNORE_UNKNOWN_CA)
InternetSetOption(SELF:hRequest,INTERNET_OPTION_SECURITY_FLAGS,@nSecur,nLen)
// Here the timeout is set
InternetSetOption(SELF:hRequest,INTERNET_OPTION_SEND_TIMEOUT,@nTimeOut,_sizeof(DWORD))
InternetSetOption(SELF:hRequest,INTERNET_OPTION_RECEIVE_TIMEOUT,@nTimeOut,_sizeof(DWORD))
InternetSetOption(SELF:hRequest,INTERNET_OPTION_CONNECT_TIMEOUT,@nTimeOut,_sizeof(DWORD))
// Send the data
IF
HttpSendRequest(SELF:hRequest,NULL,0,PTR(_CAST,cData),DWORD(_CAST,SLen(cData)))
lRet := TRUE
// Here you can downoad the updated document and the sent header
* SELF:GetResponseHeader()
* SELF:GetResponse()
// Fehler beim Senden der Daten
ELSE
SELF:PostErrorMsg := "Fehler beim Senden der Daten"
ENDIF
SELF:CloseRequest()
// Fehler beim Senden der Header-Informationen
ELSE
SELF:PostErrorMsg := "Fehler beim Senden der Header-Informationen"
ENDIF
// Fehler beim Zugriff auf das html-Dokument
ELSE
SELF:PostErrorMsg := "Fehler beim Zugriff auf das html-Dokument"
ENDIF
SELF:__DelStatusObject()
// Fehler beim Herstellen der html-Verbindung
ELSE
SELF:PostErrorMsg := "Fehler beim Herstellen der html-Verbindung"
ENDIF
// Fehler beim Zugriff auf die http-Session
ELSE
SELF:PostErrorMsg := "Fehler beim Zugriff auf die http-Session"
ENDIF
RETURN lRet
ACCESS PostErrorMsg() CLASS cHttp
// Zugriff auf eine Fehlermeldung der Methode cHttp:GetDocumentByGetOrPost()
RETURN SELF:cError
ASSIGN PostErrorMsg(cError) CLASS cHttp
// Eintragen einer Fehlermeldung in der Methode
cHttp:GetDocumentByGetOrPost()
IF IsString(cError)
SELF:cError := cError
ENDIF
RETURN SELF:cError
DEFINE INTERNET_OPTION_CONNECT_TIMEOUT := 2
DEFINE INTERNET_OPTION_RECEIVE_TIMEOUT := 6
DEFINE INTERNET_OPTION_SECURITY_FLAGS := 31
DEFINE INTERNET_OPTION_SEND_TIMEOUT := 5
DEFINE SECURITY_FLAG_IGNORE_UNKNOWN_CA := 0x00000100