Big thanks to Jamal (VO Http Post)

This forum is meant for anything you would like to share with other visitors
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Big thanks to Jamal (VO Http Post)

Post by ic2 »

We recently had to do a HTTP Post including authentication. I did have C#/X# code but for this project (not my main project) manifest issues resulting from changing the X#/C# DLL made me decide I wanted to solve this in VO. But how?

On the comp.lang NG a similar question was asked. On the always useful http://www.voug-bodensee.net Downloads there was a sample but unfortunately it returned false somewhere in the last phase. No idea why. But a few posts later Jamal wrote "Here is a sample:"....and it worked beautifully.

Jamal, once again you saved me a lot of time, thank you for that!

For others interested, below is what I made from Jamal's sample.

Dick

FUNCTION PostToDocumentOnserver(cURL AS STRING,cXMLBody AS STRING,cPostData,cUser AS STRING,cPW AS STRING) AS ARRAY PASCAL
//#s HTTP Post function 21-4-2020
//#s Jamal NG 18-9-2014
LOCAL oXMLReq AS OBJECT
LOCAL cStatus,cRetval,cHeader AS STRING

oXMLReq := OLEAutoObject{"Microsoft.XMLHTTP"}

oXMLReq:Open("POST", cURL + cPostData, FALSE) // cPostData must begin with ? first first query string, then separate with & for rest of query strings. Leave empty if no information

oXMLReq:setRequestHeader("Content-Type","application/x-www-form-urlencoded") // content-type will vary based on expected post data.
IF !Empty(cUser)
cHeader:=cUser+":"+cPW
cHeader:="Basic "+B64EncodeString(cHeader) // user:pw should be decoded
oXMLReq:setRequestHeader("Authorization",cHeader) // Set authorization if any
ENDIF
oXMLReq:Send(cXMLBody)
cStatus:=NTrim(oXMLReq:status)
cRetval:=oXMLReq:responseText // Result
RETURN {cStatus,cRetval}
Post Reply