Shoptet CURL vs Win_Ole

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Georg_BA
Posts: 108
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Shoptet CURL vs Win_Ole

Post by Georg_BA »

Hello everyone

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
I tried using the CURL function, but I could not save the received file

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
User avatar
dragancesu
Posts: 930
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Shoptet CURL vs Win_Ole

Post by dragancesu »

Windows 10 have Curl in system
Windows 7 don't have, must be install external
Georg_BA
Posts: 108
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: Shoptet CURL vs Win_Ole

Post by Georg_BA »

I use libraries

libs=hbtip
libs=hbssl
libs=libeay32
libs=ssleay32
libs=hbcurls
libs=hbcurl
libs=libcurl
libs=hbziparc
libs=hbmxml
libs=mxml

it is necessary to install something in Windows

I rather think that there is a problem in my program

thank you for your interest
Georg
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Shoptet CURL vs Win_Ole

Post by edk »

Georg_BA wrote: Tue Apr 25, 2023 1:37 pm Hello everyone

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+

thank you for your help
Georg
I think the problem is not your code (WinOLE) but the operating system. From what I can see, the https://www.shoptet.cz/ portal uses TLS v1.3 Unfortunately, Windows 7 will not support this protocol and it does not matter if it will be communication via cURL, .Net 4.x, etc.
Zrzut ekranu 2023-04-25 234859.png
Zrzut ekranu 2023-04-25 234859.png (88.16 KiB) Viewed 7979 times
Georg_BA
Posts: 108
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: Shoptet CURL vs Win_Ole

Post by Georg_BA »

thanks for the reply Edward,
I will not solve it under Windows 7

could you please check if the CURL communication is correct?

Best regards, Georg
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Shoptet CURL vs Win_Ole

Post by edk »

I don't think it will work on Win 7, but you can try the code in the attachment (of course you have to enter the actual url). I have no way to check: I don't have url data, I don't have any Win 7.
In my opinion, "forcing" unsupported systems to work with web services that require the latest protocols is pointless, because after some time any government, banking or corporate services will stop working.
So, would you expect it to work on Win XP or Win 98 SE? :lol: :lol: :lol:
Attachments
Georg_BA.zip
(1.18 MiB) Downloaded 121 times
Georg_BA
Posts: 108
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: Shoptet CURL vs Win_Ole

Post by Georg_BA »

thanks for the help Edward,
I really don't want to try using it in WIN7
your explanation was enough for me

I learn by example and your solutions are always excellent
I tried to create the same functionality using CURL
I didn't do very well :lol:
your solution still works

the only modification was that cUrl contains both the address and all requirements
I have no idea why that is, but it works

Code: Select all

Local cURL := "https://www.xxxx.sk/export/orders.xml?patternId=-11&dateFrom="+ ;
                         cDateFrom + ;
			 "&partnerId=4" + ;
			 "&dateUntil=" + ;
			 cDateUntil + ;
			 "&hash=0b37f4c1b613d9fd6aafd463714bff52f68b547d3e699c83ae0e9a024a7acf3a"

//Local cContent := "patternId=-11&dateFrom=" + cDateFrom + "&partnerId=4&dateUntil=" + cDateUntil + "&hash=" + cHash 
Local cContent := ""
curlHandle  := getCurl( curlHandle, cURL, aHeaders, cContent, cMethod )

I'm glad to have you here
you are a great asset to this forum

Sincerely Georg
Post Reply