Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #7210 > unrolled thread
| Started by | "Fred Killet" <info@killetsoft.de> |
|---|---|
| First post | 2014-09-18 13:04 +0200 |
| Last post | 2014-10-28 23:15 -0700 |
| Articles | 15 — 8 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
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
| From | "Fred Killet" <info@killetsoft.de> |
|---|---|
| Date | 2014-09-18 13:04 +0200 |
| Subject | Open url with Http Method POST |
| Message-ID | <lvee72$vb9$1@news.albasani.net> |
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
[toc] | [next] | [standalone]
| From | JohnMartens <martens@tennishulp.info> |
|---|---|
| Date | 2014-09-18 13:17 +0200 |
| Message-ID | <lveevo$ddp$1@dont-email.me> |
| In reply to | #7210 |
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
>
[toc] | [prev] | [next] | [standalone]
| From | "Fred Killet" <info@killetsoft.de> |
|---|---|
| Date | 2014-09-19 16:21 +0200 |
| Message-ID | <lvhe5t$o2i$1@news.albasani.net> |
| In reply to | #7211 |
Thank you, John, I will try it. Fred --- Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv. http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Kuno Egger <kuno@retailsoftware.com> |
|---|---|
| Date | 2014-10-25 14:44 -0700 |
| Message-ID | <250cf52c-0e05-4220-bd84-f845e0a18e1a@googlegroups.com> |
| In reply to | #7210 |
Has anyone had any luck with Norbert's Http code? I am calling it as per John's example for XML exchanges. Only difference is I don't have any param for cFolder. In any case VO 2.8b keeps reporting that InternetQueryOption is unknown. If I comment out those 3 lines the code still fails in HttpSendRequest but does not seem to return any error number or info on why it failed. The target url (https://vm.poslynx.org) responds appropriately to tests with PostMan and Http-ping. If anyone has any advice it would be welcome. Kuno
[toc] | [prev] | [next] | [standalone]
| From | norbert@kolb.cx |
|---|---|
| Date | 2014-10-26 15:47 -0700 |
| Message-ID | <ec145031-7538-4c8a-b89d-8d75625f9298@googlegroups.com> |
| In reply to | #7353 |
On Saturday, October 25, 2014 11:44:32 PM UTC+2, Kuno Egger wrote: > Has anyone had any luck with Norbert's Http code? I am calling it as per John's example for XML exchanges. Only difference is I don't have any param for cFolder. > Hi Kuno, yes I had luck <bg>. You should download my sample her http://www.voug-bodensee.net Downloads. Use something like cUrl := "www.myserver.net" cFolder := "/forum/mypage.html" Norbert
[toc] | [prev] | [next] | [standalone]
| From | Kuno Egger <kuno@retailsoftware.com> |
|---|---|
| Date | 2014-10-28 19:51 -0700 |
| Message-ID | <884f9d21-09ee-424a-ba98-0de8e2080b29@googlegroups.com> |
| In reply to | #7357 |
Hello Norbert, Yes, that is the code I have been working with but I just cannot get it to send. I can reach and get a response from the host by other means (browser, Chrome PostMan) but no joy from VO. Can cHttp send to an Https host? It fails on SendRequest() without a pause and oHttp:errormsg returns "FTP error 0". Any clues would be appreciated because I don't have one :-) Regards Kuno
[toc] | [prev] | [next] | [standalone]
| From | Mathias <mathias.hakansson@consultec.se> |
|---|---|
| Date | 2014-10-28 23:36 -0700 |
| Message-ID | <310c1398-3462-4550-9b49-6d4fc2f47d59@googlegroups.com> |
| In reply to | #7368 |
Hi Kuno,
this is the critical part of my code for downloading a file from https. The problems I had when Writing this code was determining the correct combination of flags. Maybe this is your problem too?
/Mathias
dwFlags := INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP + INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS + INTERNET_FLAG_KEEP_CONNECTION +;
INTERNET_FLAG_NO_AUTH + INTERNET_FLAG_NO_AUTO_REDIRECT + INTERNET_FLAG_NO_UI + INTERNET_FLAG_RELOAD +;
INTERNET_FLAG_SECURE
oTP:OpenRequest("GET",shttpsFile,dwFlags)
if !oTP:SendRequest(null_string,null_ptr,0)
dwRead := GetLastError()
InfoBox{,"HttpSendRequest fails","Error: " + NTrim(dwRead)}:Show()
self:__RaiseFTPError(oTP)
oTP:CloseRequest()
oTP:CloseFile(hfTP)
return 0
endif
pBuff := MemAlloc(4096)
dwRead := 4096
HttpQueryInfo(oTP:RequestHandle , HTTP_QUERY_STATUS_CODE , pBuff, @dwRead, 0L)
dwRead := Val(Mem2String(pBuff,dwRead))
MemFree(pBuff)
if dwRead != HTTP_STATUS_OK
InfoBox{,"Status error",NTrim(dwRead)}:Show()
self:__RaiseFTPError(oTP)
oTP:CloseRequest()
return 0
endif
oTP:GetResponseHeader()
Den onsdagen den 29:e oktober 2014 kl. 03:51:27 UTC+1 skrev Kuno Egger:
> Hello Norbert,
>
> Yes, that is the code I have been working with but I just cannot get it to send. I can reach and get a response from the host by other means (browser, Chrome PostMan) but no joy from VO. Can cHttp send to an Https host? It fails on SendRequest() without a pause and oHttp:errormsg returns "FTP error 0".
>
> Any clues would be appreciated because I don't have one :-)
>
> Regards
>
> Kuno
[toc] | [prev] | [next] | [standalone]
| From | norbert@kolb.cx |
|---|---|
| Date | 2014-10-29 14:58 -0700 |
| Message-ID | <7a4a3634-7e1f-412c-801f-c80070c90f2b@googlegroups.com> |
| In reply to | #7368 |
Hellom Kuno!
Try this code and you will get the html-code for this page from google.
I hope google accept the code here:
oHttp := CHttp{"VoTest"}
cPostData := ""
cPage := oHttp:GetDocumentByGetOrPost( "groups.google.com",;
"forum/#!topic/comp.lang.clipper.visual-objects/v1naK_ZnVXo",;
cPostData,;
/*cHeader*/,;
"GET",;
/*INTERNET_DEFAULT_HTTPS_PORT*/,;
INTERNET_FLAG_SECURE)
// Ergebnis protokollieren
MemoWrit( "_Header2.txt", oHttp:ResponseHeader)
MemoWrit( "_Page2.htm", cPage)
If you send me some more information I am shure I can help you.
Norbert
[toc] | [prev] | [next] | [standalone]
| From | Kuno Egger <kuno@retailsoftware.com> |
|---|---|
| Date | 2014-10-30 13:48 -0700 |
| Message-ID | <9d073b3b-ca40-40bd-98d9-940ad854f204@googlegroups.com> |
| In reply to | #7373 |
Hi Norbert,
Yes! That worked beautifully - I have a smile on my face again! Much appreciated.
Is there a way to adjust this code so it sends an xml request and reads an xml response? Here is a version of John's code that I have been trying:
////////////////////////////////////////
oHttp := CHttp{"XML exchange"}
cUrl := "vm.poslynx.org"
cFolder := "" // blank - looking for an xml response, not a specific file
cPostData := MemoRead("c:\pos_settings\http-xml.txt") // test xml request
cHeader := "Accept: *" + "/" + "*" + CrLf +"Man: POSThttp://" + cUrl + cFolder + " HTTP/1.1" + CrLf +;
"Content-Type: text/xml; charset=windows-1252" + CrLf
cPage := oHttp:GetDocumentByGetOrPost(cUrl,cFolder,cPostData,cHeader,"POST")
//////////////////////////////////
This code returns error 12029 after HttpSendRequest. Have not had luck in finding the fix.
PS - When compiling GetDocumentByGetOrPost, VO reports entity InternetQueryOption as unknown. I have to comment out the line to get it to compile.
[toc] | [prev] | [next] | [standalone]
| From | Kuno Egger <kuno@retailsoftware.com> |
|---|---|
| Date | 2014-10-30 14:49 -0700 |
| Message-ID | <5ab65fa4-890a-46be-a880-d34b8eacaac6@googlegroups.com> |
| In reply to | #7376 |
Thanks Norbert,
Here is the code that worked for my xml requests:
oHttp := CHttp{"VoTest"}
cPostData := MemoRead("c:\pos_settings\http-xml.txt")
cPage := oHttp:GetDocumentByGetOrPost( "vm.poslynx.org","/cgi/redirector",;
cPostData,;
/*cHeader*/,;
/*INTERNET_DEFAULT_HTTPS_PORT*/,;
INTERNET_FLAG_SECURE)
// Ergebnis protokollieren
MemoWrit( "_Header2.txt", oHttp:ResponseHeader)
MemoWrit( "_Page2.htm", cPage)
Any thoughts on VO reporting entity InternetQueryOption as unknown?
Thanks again.
Kuno
[toc] | [prev] | [next] | [standalone]
| From | norbert@kolb.cx |
|---|---|
| Date | 2014-10-30 17:43 -0700 |
| Message-ID | <f7f056d4-64f6-491d-b3ab-9e5f09038149@googlegroups.com> |
| In reply to | #7377 |
Hi Kuno!
> Any thoughts on VO reporting entity InternetQueryOption as unknown?
>
You have to insert the _dll-declaration:
_DLL FUNCTION InternetQueryOption ( hConnect AS PTR, ;
dwOption AS DWORD, ;
lpbuffer AS PTR, ;
lpbufferlen AS PTR;
) ;
AS LOGIC PASCAL:WININET.InternetQueryOptionA
_DLL FUNCTION InternetSetOption( hInternet AS PTR, ;
dwOption AS DWORD, ;
lpBuffer AS PTR, ;
dwBufferLength AS DWORD );
AS LOGIC PASCAL:WININET.InternetSetOptionA
They are in my sample!
Norbert
[toc] | [prev] | [next] | [standalone]
| From | Kuno Egger <kuno@retailsoftware.com> |
|---|---|
| Date | 2014-10-31 10:38 -0700 |
| Message-ID | <058d91d5-c29a-4e64-b16c-a2e76f741e6f@googlegroups.com> |
| In reply to | #7378 |
Thanks to Norbert, Mathias, Jamal and Sherlock. I appreciate the help. Kuno
[toc] | [prev] | [next] | [standalone]
| From | Sherlock <sherlock@sherlock.com.au> |
|---|---|
| Date | 2014-10-26 03:30 -0700 |
| Message-ID | <bd3cd8c5-d7a0-4192-9b05-f536da840317@googlegroups.com> |
| In reply to | #7210 |
Hope this helps with POST type syntax.
CUsername: "Phil McGuinness" CPassword: "PhilM32435"
//
cHost := "www.xxx.com.au" // http://www.xxxx.com.au/xmlApi/3
sRequest := [<?xml version="1.0" encoding="UTF-8"?>] + CRLF + ;
[<api_request>] + CRLF + ;
[<username>] + cuserName + [</username>] + CRLF + ; [<password>] + cPassword + [</password>] + CRLF + ; [<mobile_phone>] + AllTrim(cRecipientMobile) + [</mobile_phone>] + CRLF + text><![CDATA[" + AllTrim(cSMSMessage) +"]]></text>" + CRLF + ;
[</api_request>] oHttp := CHttp{ "XXXXsITE", INTERNET_DEFAULT_HTTP_PORT}
IF oHttp:ConnectRemote( SELF:cHost )
IF oHttp:OpenRequest( "POST", "/xmlApi/3/", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION )
//
sHeaders := "Content-Length: " + NTrim(SLen(sRequest)) + CRLF + "Accept-Language: en" + CRLF + "Connection: Keep-Alive" + CRLF + "Content-Type: TEXT/xml" + CRLF
//
pBuffer := StringAlloc( sRequest )
oHttp:SendRequest( sHeaders, pBuffer, SLen(sRequest) )
MemFree( pBuffer )
//
cResponseData := oHttp:GetResponse()
oHttp:CloseRequest()
oHttp := NULL_OBJECT
[toc] | [prev] | [next] | [standalone]
| From | "Jamal" <someone@example.com> |
|---|---|
| Date | 2014-10-26 16:46 -0400 |
| Message-ID | <m2jmii$gt5$1@speranza.aioe.org> |
| In reply to | #7210 |
Here is a sample:
LOCAL XMLReq AS OBJECT
LOCAL strStatus AS INT
LOCAL aRetval AS ARRAY
LOCAL xmlbody AS STRING
LOCAL cPostData AS STRING
XMLReq := OLEAutoObject{"Microsoft.XMLHTTP"}
XMLReq:open("POST", cURL + cPostData, FALSE) // cPostData must
begin with ? first first query string, then separate with & for rest of
query strings
XMLReq:setRequestHeader("Content-Type",
"application/x-www-form-urlencoded" ) // content-type will vary based on
expected post data.
XMLReq:Send(xmlbody)
strStatus := XMLReq:status
aRetval := String2array(XMLReq:responseText, ",")
Jamal
"Fred Killet" wrote in message news:lvee72$vb9$1@news.albasani.net...
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
[toc] | [prev] | [next] | [standalone]
| From | sherlocksoftwaresales@gmail.com |
|---|---|
| Date | 2014-10-28 23:15 -0700 |
| Message-ID | <12b08adb-7ca7-4270-b989-464f9b4ea7b3@googlegroups.com> |
| In reply to | #7210 |
Kuno Egger snip[ Hello Norbert, Any clues would be appreciated because I don't have one :-) ] Show us you code.. it easy once you know how and VO with native Internet classes can handle HTTP and HTTPS.. use them all the time.. works perfectly. Phil
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web