https://github.com/harbour/core/blob/ma ... /hbcurl.ch
C.
#include "FiveWin.ch"
Function Main()
local oWnd, oActiveX1, oActiveX2, cTemp
DEFINE WINDOW oWnd TITLE "FiveWin multiple ActiveX support"
@ 5, 5 BUTTON "&API TEST" OF oWnd SIZE 100, 40 ACTION TestAPI()
ACTIVATE WINDOW oWnd
return nil
function TestAPI()
local oHttp
local cUrl := "https://petstore.swagger.io/v2/pet/1000"
local hDatos := { => }
local uResponse, cCookies, I, cLink
local cData
// Data to change
cData := '{ "name": "Noyca", "status" : "available" }' // PETSTORE
// Other samples of links that maybe can help (more data insite the url)
// cUrl = "https://yoursite/api/v2/products/"+alltrim(cCode)+"?search=sku&token=yourtoken"
// This line will read the url with data and respond with uResponse.
MsgRun( cUrl, "READING API PAGE", { || uResponse := WebPageContents( cUrl, .t. ) } )
XBrowser( uResponse ) FASTEDIT
hb_JsonDecode( uResponse, @hDatos ) // -> Hash
XBrowser( hDatos ) FASTEDIT
cUrl := "https://petstore.swagger.io/v2/pet/"
oHttp := FWGetOleObject( "WINHTTP.WinHttpRequest.5.1" )
WITH OBJECT oHttp
:SetTimeouts(0, 60000, 30000, 120000)
:Open( "POST", cUrl, .f. )
:SetRequestHeader( "Accept", "application/json" )
:SetRequestHeader( "Content-Type", "application/json" )
:Send( cData )
:WaitForResponse()
? :Status, :StatusText // 200 OK
END
return nil
function _createObject()
local oOle
try
oOle := CreateObject( "msxml2.xmlhttp.6.0" )
catch
try
oOle := CreateObject( "msxml2.xmlhttp" )
catch
try
oOle := CreateObject( "microsoft.xmlhttp" )
catch
oOle := Cil
end
end
end
return oOle
function curl_test()
local pCurl := curl_easy_init()
local nRc, cBuffer, oError
try
if hb_isPointer( pCurl )
curl_easy_setopt( pCurl, HB_CURLOPT_URL, "https://harbour.page/test" )
//? curl_easy_setopt( pCurl, HB_CURLOPT_POST, .t. )
//? curl_easy_setopt( pCurl, HB_CURLOPT_POSTFIELDS, hb_jsonEncode( { "user" => "demo", "pass" => "demo" } ) )
// if need to ignore certificate
// curl_easy_setopt( pCurl, HB_CURLOPT_SSL_VERIFYPEER, .f. )
// curl_easy_setopt( pCurl, HB_CURLOPT_SSL_VERIFYHOST, .f. )
if ( nRc := curl_easy_perform( pCurl, @cBuffer ) ) == 0
? cBuffer
else
cBuffer := curl_easy_strerror( nRc )
? "error: ", cBuffer
endif
curl_easy_cleanup( pCurl )
endif
catch oError
? oError:description
end
return nil
TimStone wrote:Antonio and Lallton,
I really don't believe my question deserved those last two VERY RUDE responses.
The company I am working on has an NDA in place, so I modified the webaddress, and the user ID in the example. Everything was exactly the way I am using it. Nothing is FAKE. I was not asking you to replicate the call. It is not to a public website so you could not do that.
My last question was twofold, and simple:
1). Would Harbour cURL be better than the Microsoft based call in the original post on this thread ?
2). If the answer is yes, where can I see documenation on how to use Harbour's cURL, and is there a .prg in the Samples folder.
As one who has been a part of this community since the earliest FiveWin days, and updated every year, I don't believe such disrespectful comments were necessary, and they were not appreciated.
If you can respond to the two actual questions, I would appreciate it.
Tim
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 77 guests