Page 1 of 1

HttpClient() Chilkat replacement code

Posted: Thu Aug 29, 2024 9:30 am
by jezda
Hello everybody!

Does anyone know a chilkat replacement for this Xbase++ code:

*------------Xbase++ code
LOCAL pcSubjectCN:='ABCD Megasoft'
cUrl='https://api.sandbox.suf.purs.gov.rs/api/v3/sdc/commands'
oHC:=HttpClient():new( cURL )
oHC:setTimeout(,10000,,10000)
oHC:httpRequest:setHeader( "Accept", "application/json" )
oHC:httpRequest:setHeader( "Content-Type", "application/json" )
oHC:httpRequest:setHeader( "TaxCoreAuthenticationToken", pcToken)
oHC:httpRequest:setMethod( "GET" )
oHC:SetCertificate('user\MY\'+alltrim(pcSubjectCN))
cResponse := oHC:send()
nStatus := oHC:getStatusCode()
oHC:disconnect()
*MsgBox(var2char(nStatus))
*MsgBox(var2char(cResponse))

If nStatus=200
*--OK
Else
*--Error
Endif
This works fine on windows 10 but on windows 11 always return error ERROR_WINHTTP_SECURE_FAILURE

I wrote the following code:

*---------------------Chilkat replacement code
LOCAL pcSubjectCN:='ABCD Megasoft'
loRest = CreateObject('Chilkat_9_5_0.Rest')
lnBTls := 1
lnPort := 443
lnBAutoReconnect := 1
lnSuccess := loRest:Connect("https://api.sandbox.suf.purs.gov.rs",lnPort,lnBTls,lnBAutoReconnect)
IF lnSuccess <> 1
msgbox( "ConnectFailReason: " + STR(loRest:ConnectFailReason)+chr(13)+chr(10)+loRest:LastErrorText,'Informacija' )
RELEASE loRest
RELEASE loJson
Return nil
ENDIF
loRest:AddHeader("accept","application/json")
loRest:AddHeader("Content-Type", "application/json")
loRest:AddHeader("TaxCoreAuthenticationToken", pcToken)
loSbRequestBody := CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody := CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess := loRest:FullRequestSb("GET","/api/v3/sdc/commands",loSbRequestBody,loSbResponseBody)
IF lnSuccess <> 1
msgbox( loRest:LastErrorText,'Informacija')
RELEASE loRest
RELEASE loJson
RELEASE loSbResponseBody
Return nil
ENDIF
nstatus = loRest:ResponseStatusCode //--status
cResponse:=loSbResponseBody:GetAsString() //--response
If nStatus=200
*--OK
Else
*--Error
Endif

This works fine on both windows OS but always returns a 401 status (not autorized)
This is because i don't know how to insert authorization: oHC:SetCertificate('user\MY\'+alltrim(pcSubjectCN))

The matter is urgent and please if anyone knows the answer.

Re: HttpClient() Chilkat replacement code

Posted: Mon Sep 02, 2024 2:36 am
by reganc