Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #12346
| From | JohnMartens <martens@tennishulp.info> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| Subject | Re: HTTP POST Method with Visual Objects |
| Date | 2019-03-24 18:40 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <q78ff7$ggq$1@dont-email.me> (permalink) |
| References | <q78el1$s32$1@news.albasani.net> |
Norbert Kolb was my Guru for these kind of things. het shared his code
below in this group. I also includes other code from Bob McCutcheon that
I got in this NG.
I got XML data from a server using this call tot Norberts coes
oHttpXml := cHttp{"XML exchange"}
cPage := oHttpXml:GetDocumentByGetOrPost( cUrl,cFolder,"","","POST")
Hope it can help
John
METHOD GetDocumentByGetOrPost(cIP, cDocument, cData, cHeader, cMethod,
nP, 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)
***************************************
// 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.
***************************************
LOCAL lResult AS LOGIC
LOCAL nDataLen AS DWORD
LOCAL nBuffer AS DWORD
LOCAL nBufferLen AS DWORD
LOCAL cRet AS STRING
Default(@cDocument, "")
Default(@cData, "")
Default(@cMethod, "GET")
Default(@nP, SELF:nPort)
Default(@nFlags, 0)
IF _AND(DWORD(nFlags), INTERNET_FLAG_SECURE) = INTERNET_FLAG_SECURE
nP := INTERNET_DEFAULT_HTTPS_PORT
SELF:nPort := nP
ENDIF
IF SELF:hSession == NULL_PTR
lResult := SELF:Open(NIL, SELF:cProxy)
ELSE
lResult := .T.
ENDIF
IF lResult
// Identify the type of service that is being accessed
IF SELF:hConnect == NULL_PTR .OR. SELF:cHostAddress <> cIP
SELF:cHostAddress := cIP
SELF:hConnect := InternetConnect(SELF:hSession, ;
String2Psz(SELF:cHostAddress), ;
nP, ;
String2Psz(SELF:cUserName), ;
String2Psz(SELF:cPassword), ;
INTERNET_SERVICE_HTTP, ;
nFlags, ;
0)
ENDIF
IF SELF:hConnect <> NULL_PTR
SELF:__SetStatusObject()
// Once we've identified the service, we need to indicate the
// page to which the data will be posted. In this example, it will
// be "/getorpost.php"
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
IF SELF:hRequest <> NULL_PTR
SELF:__SetStatus(SELF:hRequest)
// We need to add a header to notify the web server that the
// incoming data is form encoded and then send the request.
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
IF HttpAddRequestHeaders(SELF:hRequest, ;
String2Psz(cHeader), ;
SLen(cHeader), ;
HTTP_ADDREQ_FLAG_ADD)
// Sometimes you have to set SECURITY_FLAGS
InternetQueryOption(SELF:hRequest, INTERNET_OPTION_SECURITY_FLAGS,
@nBuffer, @nBufferLen)
nBuffer := _OR(nBuffer, SECURITY_FLAG_IGNORE_UNKNOWN_CA)
InternetSetOption(SELF:hRequest, INTERNET_OPTION_SECURITY_FLAGS,
@nBuffer, nBufferLen)
nDataLen := SLen(cData)
IF HttpSendRequest(SELF:hRequest, ;
NULL, ;
0, ;
PTR(_CAST, cData), ;
nDataLen)
// Finally, we need to collect our reward for all this effort
SELF:GetResponseHeader()
cRet := SELF:GetResponse()
ENDIF // SendRequest
SELF:CloseRequest()
END // AddRequestHeaders
ENDIF
SELF:__DelStatusObject()
ENDIF
ENDIF
RETURN cRet
METHOD PostToDocumentOnServer(cServer, cDocument,cCargo, cID, cPw) CLASS
cHttp // String
// Bob McCutcheon
// VO NG Wed 25 Sept 2002 21:46
// LOCAL ohttp:=myhttp{}
//
ohttp:PostToDocumentOnserver("https://www.ups.com/ups.app/xml/Track","c:\ACCESS.xml","testUser","testPW")
LOCAL cRet := '' AS STRING
LOCAL pCargo AS PTR
LOCAL cContentType AS STRING
LOCAL lOpen AS LOGIC
LOCAL lSend AS LOGIC
//LOCAL accepttype,acceptlang AS STRING
LOCAL acceptencoding AS STRING
//LOCAL referer, User_agent AS STRING
LOCAL nfile,clin:="",cdoc:=""
Default(@cServer, URL_LOCAL_HOST)
Default(@cDocument, "")
IF File(cdocument)
IF (nfile:=FOpen(cdocument)) != F_ERROR
DO WHILE ! FEof(nfile)
cdoc+=clin
ENDDO
FClose(nfile)
SELF:ConnectRemote(cServer, cID, cPw)
IF SELF:Connected
cContentType:="Content-Length: " + Str(Len(cdoc))+CRLF
cContentType+="Accept-Language: en" +CRLF
cContentType+="Connection: Keep-Alive" +CRLF
cContentType+="Content-Type: application/x-www-form-urlencoded" + CrLf
ACCEptEncoding := "Accept-Encoding: gzip, deflate"
lOpen := SELF:OpenRequest("POST",cdoc, "HTTP/1.0")
IF lOpen
//sHeader := "Content-Length: 2048" + CrLf
lSend :=
SELF:SendRequest(cContentType,PTR(_CAST,pcargo),WORD(_CAST,Len(cDoc)))
IF lSend
cRet := SELF:GetResponse()
ELSE
cRet := 'FOUT: verzending naar '+cServer+' mislukt.'
ENDIF
MemFree(pcargo)
SELF:CloseRequest()
ELSE
cRet := 'FOUT: verzoek bij '+cServer+' mislukt.'
ENDIF
SELF:CloseRemote()
ELSE
cRet := 'FOUT: geen verbinding kunnen maken met '+cServer+'.'
ENDIF
ELSE
cRet := 'FOUT: '+cdocument+' kan niet geopend worden.'
ENDIF
ELSE
cRet := 'FOUT: '+cdocument+' bestaat niet.'
ENDIF
RETURN cRet
Op 24-3-2019 om 18:26 schreef Fred Killet:
> Hallo,
> ist es möglich mit Visual Objects Daten mit der HTTP POST Methode zu
> einem Server zu schicken? Hat jemand ein Code-Beispiel?
> Danke für die Mühe,
> Fred
>
> Hello,
> is it possible to use Visual Objects to send data to a server using the
> HTTP POST method? Does anyone have a code sample?
> Thank you for the effort,
> Fred
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
HTTP POST Method with Visual Objects Fred Killet <info_nospam_@killetsoft.de> - 2019-03-24 18:26 +0100
Re: HTTP POST Method with Visual Objects JohnMartens <martens@tennishulp.info> - 2019-03-24 18:40 +0100
Re: HTTP POST Method with Visual Objects "Wolfgang Riedmann" <wriedmann@gmail.com> - 2019-03-25 10:07 +0100
Re: HTTP POST Method with Visual Objects Johan Nel <johan.nel@xsinet.co.za> - 2019-03-25 14:01 +0200
Re: HTTP POST Method with Visual Objects nk <norbert.k@chello.at> - 2019-03-26 00:26 +0100
Re: HTTP POST Method with Visual Objects "Wolfgang Riedmann" <wriedmann@gmail.com> - 2019-03-26 11:55 +0100
Re: HTTP POST Method with Visual Objects nk <norbert.k@chello.at> - 2019-03-26 15:08 +0100
Re: HTTP POST Method with Visual Objects HeG Ti <hegasaf@gmail.com> - 2021-09-30 11:28 -0700
Re: HTTP POST Method with Visual Objects Fred Killet <info_nospam_@killetsoft.de> - 2019-03-30 12:02 +0100
Re: HTTP POST Method with Visual Objects JohnMartens <martens@tennishulp.info> - 2019-03-30 21:45 +0100
Re: HTTP POST Method with Visual Objects Fred Killet <info_nospam_@killetsoft.de> - 2019-04-02 01:08 +0200
Re: HTTP POST Method with Visual Objects Heraldo Gama <heraldogama@gmail.com> - 2021-09-30 11:55 -0700
csiph-web