Page 1 of 1

mod bug solved ->Charly

PostPosted: Wed Nov 10, 2021 5:23 pm
by wilsongamboa
Good afternoon to everyone
Thanks to the invaluable work of our GURU Charly has solved a bug in the Mod_Harbour regarding the use of CURL when calling a WebService Thank you Charly!!
now it works perfect!! because the parameters did not receive them!!
this already works Ok
Code: Select all  Expand view

#include "{% hb_getenv('PRGPATH') + '/hbcurl.ch' %}"

function Main()
   
    local h := UseWebService()
   
    AP_SetContentType( "application/json" )
   
    ?? hb_jsonEncode(h)

retu nil

function UseWebService()

    local uValue, hCurl
    local cUrlWs        := '190.110.XXX.YYY:6263/pre/jnetws/auth'
    local hHeaders  := { 'Content-Type: application/json' }  
    local hParams       := {=>}
    local h             := {=>}
    local n


    hParams[ 'wsuser' ]     := 'app1'
    hParams[ 'wspsw' ]  := 'acvbs'
    hParams[ 'user' ]       := 'demo'
    hParams[ 'psw' ]        := '1129'
    hParams[ 'emp' ]        := 'Empre003'

    curl_global_init()

    if ! empty( hCurl := curl_easy_init() )

        curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, 0)            
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrlWs )
        curl_easy_setopt( hCurl, HB_CURLOPT_HTTPHEADER, hHeaders )
        curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1 )  
        curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, hb_jsonEncode( hParams ) )

        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )        
       
        n := curl_easy_perform( hCurl )
       
        if n == 0
       
            uValue  := curl_easy_dl_buff_get( hCurl )          
            h       := hb_jsonDecode( uvalue )
           
        else
            h[ 'error' ] := curl_easy_strerror( n )
        endif
    endif

    curl_global_cleanup()

return h