I would need help with communication via CURL
it is about downloading orders from the platform Shoptet
I have created a function that works without problems, but only under Windows 10+
Code: Select all
function obj_shoptet(d1,d2)
hash=ed71314334570724bcff62bb29dabf4c5fb91cca7bc774bc9873895a6b676a8f
local d1c:=dtoc(d1), d2c:=dtoc(d2)
hash=ed71314334570724bcff62bb29dabf4c5fb91cca7bc774bc9873895a6b676a8f"
Local cURL := "https://www.xxxx.sk/export/orders.xml?patternId=-11&dateFrom="+ ;
substr(d1c,7,4)+"-"+substr(d1c,4,2)+"-"+substr(d1c,1,2) + ;
"&partnerId=4" + ;
"&dateUntil=" + ;
substr(d2c,7,4)+"-"+substr(d2c,4,2)+"-"+substr(d2c,1,2) + ;
"&hash=0b37f4c1b613d9fd6aafd463714bff52f68b547d3e699c83ae0e9a024a7acf3a"
Local cPOSTdata
LOCAL cResp, hRest, oWeb
local hCurl
//vymazem stary linux subor
DeleteFile(cesta1+'SHOPTET\shoptet_'+Alltrim(STR(moje_cislo,3,0))+'.xml')
//vymazem stary PC subor
DeleteFile(cesta1+'SHOPTET\shoptet_'+Alltrim(STR(moje_cislo,3,0)+'D')+'.xml')
if .t.
// win7 no ok , win10 ok
//Init
BEGIN SEQUENCE WITH {|o| break(o)}
oWeb := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
RECOVER
MsgStop( "Microsoft XML Core Services (MSXML) 6.0 is not installed."+CRLF+;
"Download and install MSXML 6.0 from http://msdn.microsoft.com/xml"+CRLF+;
"before continuing.")
oWeb:=""
END SEQUENCE
IF EMPTY(oWeb)
MsgStop("Error while init.")
RETURN
ENDIF
cResp := SendRequest01( cUrl, cPOSTdata, oWeb )
IF cResp = "!ERROR!"
MsgStop( cResp ) /* Report any errors */
ELSE
hResp := hb_jsonDecode( cResp )
//MsgDebug( cResp )
//MsgDebug( hResp )
StrFile(cResp, cesta1+'SHOPTET\shoptet_'+Alltrim(STR(moje_cislo,3,0))+'.xml')
ENDIF
//Close
oWeb:Abort()
endif
my attempt
Code: Select all
if .f.
//test curl
cURL := "https://www.xxxx.sk/export/orders.xml?patternId=-11&dateFrom="+ ;
substr(d1c,7,4)+"-"+substr(d1c,4,2)+"-"+substr(d1c,1,2) + ;
"&partnerId=4" + ;
"&dateUntil=" + ;
substr(d2c,7,4)+"-"+substr(d2c,4,2)+"-"+substr(d2c,1,2) + ;
"&hash=0b37f4c1b613d9fd6aafd463714bff52f68b547d3e699c83ae0e9a024a7acf3a"
cfile:=cesta1+'SHOPTET\shoptet_'+Alltrim(STR(moje_cislo,3,0))+'.xml'
curl_global_init()
IF !empty( hCurl := curl_easy_init() )
//curl_easy_setopt( hCurl, HB_CURLOPT_HTTPHEADER, {"Content-Type:application/xml","Accept: application/xml"} )
//curl_easy_setopt( hCurl, HB_CURLOPT_HTTPGET, .T. ) //Setup this handle only for GET method so you dont have to change the curl_options for it everytime.
//curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
//curl_easy_setopt( hCurl, HB_CURLOPT_TRANSFERTEXT, .T. )
//curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, .T. )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
//curl_setopt($curl, CURLOPT_URL, $url) //php
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cURL )
//curl_setopt($curl, CURLOPT_RETURNTRANSFER, true) //php
curl_easy_setopt( hCurl, HB_CURLOPT_TRANSFERTEXT, .T. )
//curl_easy_setopt($curl, HB_CURLOPT_RETURNTRANSFER, .t.) //hmg not exist HB_CURLOPT_RETURNTRANSFER
//$headers = array( "Accept: application/xml",);
//curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_easy_setopt( hCurl, HB_CURLOPT_HTTPHEADER, {"Accept: application/xml",""} )
aa:=curl_easy_perform( hCurl )
msginfo( curl_easy_dl_buff_get( hCurl ) )
//msginfo( aa )
//curl_easy_dl_buff_get( hCurl )
nHandle := FCREATE( cfile )
FWRITE( nHandle, curl_easy_dl_buff_get( hCurl ) )
//FWRITE( nHandle, aa )
FCLOSE( nHandle )
curl_easy_reset( hCurl )
ENDIF
curl_global_cleanup()
endif
thank you for your help
Georg