Page 1 of 1

libcurl issues

Posted: Fri Feb 10, 2023 10:48 pm
by TimStone
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.

Re: libcurl issues

Posted: Sat Feb 11, 2023 5:02 am
by Jimmy
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

Re: libcurl issues

Posted: Sat Feb 11, 2023 5:14 am
by TimStone
Thank you


Sent from my iPhone using Tapatalk

Re: libcurl issues

Posted: Sat Feb 11, 2023 7:16 am
by TimStone
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

  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

  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

--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.

Re: libcurl issues

Posted: Sat Feb 11, 2023 10:01 am
by cmsoft
Tim, no se si esto es lo que buscas, como generar ese json

Code: Select all | Expand

#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

Re: libcurl issues

Posted: Sat Feb 11, 2023 5:09 pm
by TimStone
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.

Re: libcurl issues

Posted: Sun Feb 12, 2023 3:47 am
by cnavarro
Try with

Code: Select all | Expand

   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