How to impliment in Msxml2.ServerXMLHTTP.6.0

436 views
Skip to first unread message

Vikram Chhajer

unread,
Jun 2, 2021, 1:30:40 AM6/2/21
to Harbour Users
Hello Experts  
please help me to write this code in Msxml2.ServerXMLHTTP.6.0 


curl -i -X POST "https://upload.box.com/api/2.0/files/content" \ -H "Authorization: Bearer <ACCESS_TOKEN>" \ -H "Content-Type: multipart/form-data" \ -F attributes="{"name":"Contract.pdf", "parent":{"id":"11446498"}}" \ -F file=@<FILE_NAME>


Thank you 
Vikram

Shaji Thomas

unread,
Jun 2, 2021, 4:33:18 AM6/2/21
to Harbour Users
Hi Vikram,

First of all, I am not an EXPERT in this subject..
I am using ServerXMLHTTP for a data uploading session from client side. 


Function OpenHTTP(cType)
LOCAL oHTTP

if (oHTTP := win_oleCREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')) == NIL
?  "ERROR.. Msxml2.ServerXMLHTTP.6.0 object creation failed.."
RETURN NIL
endif

return (oHTTP)
**--------------------------------------------------------------------------**
Function PostHTTP(oHTTP,  cUrl, lGet)
local cRetVal := "", nCounter := 0, oErr

DEFAULT lGet to .f. // GET or POST

BEGIN SEQUENCE with {|oErr|break(oErr)}
if lGet
oHTTP:OPEN("GET", cUrl, .F.) // search
else
oHTTP:OPEN("POST", cUrl, .F.) // upload
endif

oHTTP:SEND()

do while nCounter < 500000

if oHTTP:ReadyState == 4
EXIT
endif

if nCounter > 100
?   "[" + hb_ntos(nCounter) + "] HTTP ReadyState => " + hb_ntos(oHTTP:ReadyState)  // just for info 
endif
++nCounter
enddo

if ! oHTTP:status == 200
  ?  "HTTP Status => [" + hb_ntos(oHTTP:Status) + "] " + oHTTP:StatusText
endif

cRetVal := oHTTP:responseText
cRetVal := strtran(cRetVal, chr(13))

RECOVER using oErr

cRetVal := alltrim(strtran(oErr:description, chr(13)))
hb_alert("Error occured while processing HTTP request :-" + ";;" + ;
cRetVal, NIL, "r/gr", 10)

cRetVal := ""

END SEQUENCE

if empty(cRetVal)
?  "Empty Response Text from website.."
endif

return (cRetVal)
**--------------------------------------------------------------------------**
Read the ServerXMLHTTP help document from microsoft or others  for using  "Content-Type: multipart/form-data" and other settings ..
I am using url encoded string and this string is an extension to the  server name. So I do not have to use parameters in SEND() method..

In your case,  you need to use the SEND() method parameters to send data. Go through the OPEN(), GET & SEND() methods and sample codes..

Open(....) user name and password can be used here..(not tested)
oHTTP:SetRequestHeader( "Content-Type",  "multipart/form-data") 
Send(...)

Regards..
Shaji Thomas

Vikram Chhajer

unread,
Jun 2, 2021, 11:54:46 PM6/2/21
to Harbour Users
THANKS SIR 
BUT DID'NT UNDERSTAND PLEASE MAKE IT CLEAR TO UNDERSTAND

THANKS

Reply all
Reply to author
Forward
0 new messages