libcurl issues

libcurl issues

Postby TimStone » Fri Feb 10, 2023 10:48 pm

I have successfully used libcurl for some processes, but for a new task, I have uncovered two issues:

curl_easy_setopt(hCurl, HB_CURLOPT_FOLLOWLOCATION, 1L). When trying to compile this, Harbour errors at the L ( in 1L ). This is a standard call.

curl_easy_setopt(hCurl, HB_CURLOPT_DEFAULT_PROTOCOL, "https"). This line errors because the hbcurl.ch does not have a listing for DEFAULT_PROTOCOL

These are two standard libcurl settings. My include file is from the latest version of Harbour supplied by FiveTech.

Any assistance would be appreciated.

I do have the right libraries linked in. I also have curl running smoothly on other tasks.

Thank you.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: libcurl issues

Postby Jimmy » Sat Feb 11, 2023 5:02 am

hi Tim,
TimStone wrote: curl_easy_setopt(hCurl, HB_CURLOPT_DEFAULT_PROTOCOL, "https").

there is not HB_CURLOPT_DEFAULT_PROTOCOL but HB_CURLOPT_PROTOCOLS
you can use it with HB_CURLPROTO_HTTPS or HB_CURLPROTO_HTTP
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: libcurl issues

Postby TimStone » Sat Feb 11, 2023 5:14 am

Thank you


Sent from my iPhone using Tapatalk
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: libcurl issues

Postby TimStone » Sat Feb 11, 2023 7:16 am

Sometimes no matter how long you look at something, the answer just doesn't come, even when trying multiple approaches. This is one of them.

Still using libcurl:

This is a working format in straight c-libcurl:

Code: Select all  Expand view  RUN

  const char *data = "{\r\n  \"transactionData\": {\r\n    \"transactionType\": \"CreditSale\",\r\n    \"method\": \"hostedFields\",\r\n    \"submissionType\": \"automatic\",\r\n    \"fields\": [\r\n      {\r\n        \"id\": \"base_amount\",\r\n        \"value\": \"1.00\"\r\n      },\r\n      {\r\n        \"id\": \"external_tran_id\",\r\n        \"value\": \"ae898295-c8b8-4799-b2c1-88e5067be721\"\r\n      },\r\n      {\r\n         \"id\": \"device_name\",\r\n        \"value\": \"Flex-0554\"\r\n      }\r\n    ]\r\n  }\r\n}";

 


Here is the same code in PHP-CURL:

Code: Select all  Expand view  RUN

  CURLOPT_POSTFIELDS =>'{
  "transactionData": {
    "transactionType": "CreditSale",
    "method": "hostedFields",
    "submissionType": "automatic",
    "fields": [
      {
        "id": "base_amount",
        "value": "1.00"
      },
      {
        "id": "external_tran_id",
        "value": ""
      },
      {
         "id": "device_name",
        "value": "Flex-0554"
      }
    ]
  }
}'
,

 


and in straight cURL:

Code: Select all  Expand view  RUN

--data-raw '{
  "transactionData": {
    "transactionType": "CreditSale",
    "method": "hostedFields",
    "submissionType": "automatic",
    "fields": [
      {
        "id": "base_amount",
        "value": "1.00"
      },
      {
        "id": "external_tran_id",
        "value": ""
      },
      {
         "id": "device_name",
        "value": "Flex-0554"
      }
    ]
  }
}'


 


These are values for cPostFields to pass with curl_easy_setopt(hCurl, HB_CURLOPT_POSTFIELDS, cPostFields).

I've viewed a lot of samples, and tried approaches, but I cannot find a "Harbour friendly" format to write this string. Anyone confident on how to approach this ?

Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: libcurl issues

Postby cmsoft » Sat Feb 11, 2023 10:01 am

Tim, no se si esto es lo que buscas, como generar ese json
Code: Select all  Expand view  RUN

#include "fivewin.ch"
function main()
LOCAL aData, aField, aRecord, aFields1 := {}, cJson
aData   := hash()
aRecord := hash()

aRecord["transactionType"] = "CreditSale"
aRecord["method"]          = "hostedFields"
aRecord["submissionType"]  = "automatic"

aField  := hash()
aField["id"]    =  "base_amount"
aField["value"] =  "1.00"
AADD(aFields1,aField)
aField  := hash()
aField["id"]    =  "external_tran_id"
aField["value"] =  ""
AADD(aFields1,aField)
aField  := hash()
aField["id"]    =  "device_name"
aField["value"] =  "Flex-0554"
AADD(aFields1,aField)
aRecord["fields"] = aFields1

aData["transactionData"] = aRecord
cJson := hb_jsonEncode(aData,.f.)
memowrit("json.txt",cJson)
return nil
 

Mira el archivo json.txt para ver el resultado si es el esperado
Espero te sea de utilidad
User avatar
cmsoft
 
Posts: 1291
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: libcurl issues

Postby TimStone » Sat Feb 11, 2023 5:09 pm

I don't know that I have to encode the string as json. I have done that for other external systems where I'm passing data.

The examples I have provided were all being sent directly, as shown, to the website using "Postman". They work correctly. However, they are all variants from the Harbour code ( or FWH samples I see ) using libcurl.

Any other thoughts ?

Yes ... I can test this to see if it works but I think it's really just how I format the data similar to how the examples show, but that Harbour can actually use.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: libcurl issues

Postby cnavarro » Sun Feb 12, 2023 3:47 am

Try with
Code: Select all  Expand view  RUN

   Local cRequest

   TEXT INTO cRequest
{
  "transactionData": {
    "transactionType": "CreditSale",
    "method": "hostedFields",
    "submissionType": "automatic",
    "fields": [
      {
        "id": "base_amount",
        "value": "1.00"
      },
      {
        "id": "external_tran_id",
        "value": ""
      },
      {
         "id": "device_name",
        "value": "Flex-0554"
      }
    ]
  }
}
   ENDTEXT

   ? cRequest

   

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Otto and 60 guests