Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #7211
| From | JohnMartens <martens@tennishulp.info> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| Subject | Re: Open url with Http Method POST |
| Date | 2014-09-18 13:17 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <lveevo$ddp$1@dont-email.me> (permalink) |
| References | <lvee72$vb9$1@news.albasani.net> |
Hi Fred,
Norbert Kolb is the guru on this.
This is a class he shared in this NG.
This is an example of how I called it:
oHttpAfhangbord := cHttp{"XML exchange"}
cUrl := "xml.mysite.nl"
cFolder := "/service/Import.aspx?k="+cMtcsKey
cPostData := MemoRead(cMyXmlFile)
cHeader := "Accept: *" + "/" + "*" + CrLf +;
"Man: POSThttp://" + cUrl + cFolder + " HTTP/1.1" + CrLf +;
"Content-Type: text/xml; charset=windows-1252" + CrLf
cPage := oHttpAfhangbord:GetDocumentByGetOrPost(
cUrl,cFolder,cPostData,cHeader,"POST")
oHttpAfhangbord:CloseRemote()
oHttpAfhangbord:Axit()
Hope it helps
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
Fred Killet schreef op 18-9-2014 om 13:04:
> Hello,
>
> I like to send some data from a Visual Objects program to an URL using
> the POST method.
>
> How to do that with the GET method I know:
> ShellExecute(SELF:handle(),PSZ("open"),PSZ(cText),NULL,NULL,SW_SHOWNORMAL)
>
> But is there a way to do it with the POST method? Is there an example?
>
> Thanks for your help.
>
>
> Fred Killet
> killet-nospam@killetsoft.de
>
> ---
> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
> Schutz ist aktiv.
> http://www.avast.com
>
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Open url with Http Method POST "Fred Killet" <info@killetsoft.de> - 2014-09-18 13:04 +0200
Re: Open url with Http Method POST JohnMartens <martens@tennishulp.info> - 2014-09-18 13:17 +0200
Re: Open url with Http Method POST "Fred Killet" <info@killetsoft.de> - 2014-09-19 16:21 +0200
Re: Open url with Http Method POST Kuno Egger <kuno@retailsoftware.com> - 2014-10-25 14:44 -0700
Re: Open url with Http Method POST norbert@kolb.cx - 2014-10-26 15:47 -0700
Re: Open url with Http Method POST Kuno Egger <kuno@retailsoftware.com> - 2014-10-28 19:51 -0700
Re: Open url with Http Method POST Mathias <mathias.hakansson@consultec.se> - 2014-10-28 23:36 -0700
Re: Open url with Http Method POST norbert@kolb.cx - 2014-10-29 14:58 -0700
Re: Open url with Http Method POST Kuno Egger <kuno@retailsoftware.com> - 2014-10-30 13:48 -0700
Re: Open url with Http Method POST Kuno Egger <kuno@retailsoftware.com> - 2014-10-30 14:49 -0700
Re: Open url with Http Method POST norbert@kolb.cx - 2014-10-30 17:43 -0700
Re: Open url with Http Method POST Kuno Egger <kuno@retailsoftware.com> - 2014-10-31 10:38 -0700
Re: Open url with Http Method POST Sherlock <sherlock@sherlock.com.au> - 2014-10-26 03:30 -0700
Re: Open url with Http Method POST "Jamal" <someone@example.com> - 2014-10-26 16:46 -0400
Re: Open url with Http Method POST sherlocksoftwaresales@gmail.com - 2014-10-28 23:15 -0700
csiph-web