Page 1 of 1

CURL_GLOBAL_INIT()

Posted: Tue Apr 06, 2021 3:22 pm
by ctoas
Hello friends.

I'm starting a function using cURL and right at the beginning in "CURL_GLOBAL_INIT()" it gives me an error according to the image.

Image

Would anyone know what it can be?

Thanks

Re: CURL_GLOBAL_INIT()

Posted: Tue Apr 06, 2021 4:41 pm
by Antonio Linares
Christiano,

Please post here a small PRG that reproduces the error, thanks

Re: CURL_GLOBAL_INIT()

Posted: Tue Apr 06, 2021 5:39 pm
by hmpaquito

Re: CURL_GLOBAL_INIT()

Posted: Tue Apr 06, 2021 6:21 pm
by ctoas
Antonio, thank you for answering.

Follows the code of what I'm doing

Code: Select all | Expand


#INCLUDE "FIVEWIN.CH"
#INCLUDE "HBCURL.CH"

FUNCTION TESTE()

    LOCAL ClientID     := "Client_Id_845d87fc2a97b8b4a8aada2f0d9df2aceca50031"
    LOCAL ClientSecret := "Client_Secret_57917244d7a42f96ff2c1ec4e6eeb0740f61eb6c"
    LOCAL hWebService

    CURL_GLOBAL_INIT()
    hWebService := CURL_EASY_INIT()
   
    IF !EMPTY(hWebService)
       
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_URL, "https://sandbox.gerencianet.com.br/v1/charge/one-step")
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_RETURNTRANSFER, .T.)
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_ENCODING, '')
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_MAXREDIRS, 10)
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_TIMEOUT, 0)
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_FOLLOWLOCATION, .T.)
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1)
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_CUSTOMREQUEST, "POST")
//      CURL_EASY_SETOPT(hWebService, HB_CURLOPT_POSTFIELDS, {"items": {"name": "Product 1",;
//                                                                      "value": 500,;
//                                                                      "amount": 1},;
//                                                            "shippings": {"name": "Default Shipping Cost",;
//                                                                          "value": 100},                  ;
//                                                            "payment": {"banking_billet": {"expire_at": "2019-10-16",;
//                                                                                           "customer": {"name": "Gorbadoc Oldbuck",;
//                                                                                           "email": "gorb.oldbuck@gerencianet.com.br",;
//                                                                                           "cpf": "14014603059",;
//                                                                                           "birth": "1977-01-15",;
//                                                                                           "phone_number": "62986070247"}}}})
        CURL_EASY_SETOPT(hWebService, HB_CURLOPT_HTTPHEADER,array('Authorization: {{Authorization}}','Content-Type: application/json'))
   
    ENDIF
   
    CURL_GLOBAL_CLEANUP()

RETURN NIL
 

Re: CURL_GLOBAL_INIT()

Posted: Wed Apr 07, 2021 8:06 am
by Antonio Linares

Re: CURL_GLOBAL_INIT()

Posted: Thu Apr 08, 2021 5:38 pm
by ctoas
Hello Mr. Antonio

I removed the code CURL_GLOBAL_INIT () and CURL_GLOBAL_CLEANUP () as mentioned in your answer and stopped the error. Thank you!

Now if possible I would have two more doubts.

1st - In the PHP code I am using as a reference there is the command:

Code: Select all | Expand

$ response = curl_exec ($ curl);


what is your correspondence in HB_CURL?

2nd - Regarding CURL_EASY_INIT (), wouldn't you have to close it with an IF?

Thank you!

Re: CURL_GLOBAL_INIT()

Posted: Fri Apr 09, 2021 10:48 am
by Antonio Linares
I would say it is curl_easy_perform( hCurl )

viewtopic.php?p=240120&sid=f48eff6a559c156b39000315c6649994#p240120

> 2nd - Regarding CURL_EASY_INIT (), wouldn't you have to close it with an IF?

Yes, right