How to include hbCurl?

How to include hbCurl?

Postby Otto » Sun Mar 03, 2024 12:06 am

Hello friends,

How to include hbCurl? Is it working in xHarbour, too?

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to include hbCurl?

Postby TimStone » Sun Mar 03, 2024 12:24 am

Otto,

I include, in a .mak file, the following:
echo $(HBDIR)\lib\hbtipssl.lib >> msvc.tmp
echo $(HBDIR)\lib\hbcurl.lib >> msvc.tmp
echo $(HBDIR)\lib\libcurl.lib >> msvc.tmp

I do my builds with Harbor and MSVC

It works fine. Also include the libcurl.dll

It also works for 64 bit with those libraries and the 64 bit dll

Tim
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: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: How to include hbCurl?

Postby Otto » Sun Mar 03, 2024 8:22 am

Hello Tim,
thank you for your help.

While I was looking for a solution yesterday to make cUrl common in my desktop program, I then tried a solution with the command prompt and shellExecute. That works well.
What are the disadvantages of shellExec()? I have been using 7Zip in this way for years.

On the whole, the path with shellExEc() would seem more maintenance-friendly to me if you would otherwise have no issues or only have to deal with the firewall during the initial setup.

Best regards,
Otto

Code: Select all  Expand view
c:\curl-8.6.0_3-win64-mingw\bin\curl.exe -u username:password -k -F "fileToUpload=@c:\xxxx\tmpplan\planangebot.dbf" https://test.com/webservices/responderdbf.php
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to include hbCurl?

Postby Antonio Linares » Sun Mar 03, 2024 8:57 am

Dear Otto,

> What are the disadvantages of shellExec()?

I guess the only problem is that the user does not have curl.exe installed or at the right path
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to include hbCurl?

Postby Enrico Maria Giordano » Sun Mar 03, 2024 11:16 am

Otto wrote:Hello friends,

How to include hbCurl? Is it working in xHarbour, too?

Best regards,
Otto


Hi Otto,

Yes, it is working with xHarbour too. You have to link hbcurl.lib and libcurl.lib. Then you must have libcurl.dll in the same folder of the EXE (or in the path, of course).
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to include hbCurl?

Postby vensanto » Wed Mar 06, 2024 5:33 am

HI,
you can generate C code from the CURL command line
adding "--libcurl filename.c" to the end of the command line

below is an example:
curl http://example.com --libcurl example.c

look at the link
https://everything.curl.dev/libcurl/libcurl
User avatar
vensanto
 
Posts: 58
Joined: Thu Oct 13, 2005 1:26 pm
Location: ITALIA

Re: How to include hbCurl?

Postby Otto » Thu Mar 07, 2024 7:15 pm

Hello friends,
Thank you for your help.
I have now solved it with the command prompt Exe.

On this occasion, I started creating the setup program with webview2 and fivewin.

Fortunately, I had already made a patcher and preprocessor before ChatGPT.
Now, this is a very functional way to simplify the programs. Through modularization, one can have ChatGPT further develop parts of the program very effectively. This makes program creation very fast.

Best regards,
Otto


Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to include hbCurl?

Postby Marc Venken » Fri Mar 08, 2024 10:04 pm

TimStone wrote:Otto,

I include, in a .mak file, the following:
echo $(HBDIR)\lib\hbtipssl.lib >> msvc.tmp
echo $(HBDIR)\lib\hbcurl.lib >> msvc.tmp
echo $(HBDIR)\lib\libcurl.lib >> msvc.tmp

I do my builds with Harbor and MSVC

It works fine. Also include the libcurl.dll

It also works for 64 bit with those libraries and the 64 bit dll

Tim


Tim,

Are you using cUrl for reading API's ? By any change the API from Mailchimp ?

curl -sS "https://us8.api.mailchimp.com/3.0/ping" --user "anystring:cApi"

I want to read the result from this command insite FW. and give the command also from FW
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: How to include hbCurl?

Postby Otto » Fri Mar 08, 2024 10:41 pm

Marc, you can redirect to a file: clogrooms and then read with memoread.
Regards,
Otto
DCOM := 'cmd /c "' +;
cCurlPath + 'curl.exe -u username:password -i -k -F "fileToUpload=@' +;
aSrc[I] + '" -F "uploadDirectory=' + cuploadDirectory + '" ' +;
cEndpointRooms + ' > ' +;
clogrooms + '"'

WAITRUN( DCOM, 0)
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to include hbCurl?

Postby Marc Venken » Sat Mar 09, 2024 8:53 pm

Otto, Thanks for the sample.

I got it working now to read with cUrl...

Now digging into the hard part of getting all elements :D
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: How to include hbCurl?

Postby Marc Venken » Tue Mar 19, 2024 10:13 pm

I can read several data with the API, but struggle with the one that can change a TAG (like a groupname) into Mailchimp.

This is working, and I get the tags from a email

DCOM := 'cmd /c curl -sS https://us8.api.mailchimp.com/3.0/lists ... ail+'/tags --user anystring:'+cApi+' > clogrooms.txt'

In order to add a Tag this should be executed, but I allways fale in passing the correct data

This is NOT working

DCOM := 'cmd /c curl -sS https://us8.api.mailchimp.com/3.0/lists ... members/';
+cSecure_Email+'/tags --user anystring:';
+cApi+'-d tags:'+aTags+',is_syncing:false';
+' > clogrooms.txt'

and Mailchimp api says :

curl -X POST \
https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/members/{subscriber_hash}/tags \
--user "anystring:${apikey}"' \
-d '{"tags":[],"is_syncing":false}'

By any change that somebody knows how to do it ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: How to include hbCurl?

Postby Otto » Wed Mar 20, 2024 4:59 am

Marc, have yout tried the answer ChatGPT gives you?
Best regards,
Otto

It seems like you're trying to add tags to a member in a MailChimp list using the MailChimp API and curl in a command line environment. The issue appears to be with the way you're formatting the JSON data in your curl command. Let's break down the correct format and structure for your curl command to add tags to a member.

Here's the general format you need to follow based on Mailchimp's documentation:

```bash
curl -X POST \
https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/members/{subscriber_hash}/tags \
--user "anystring:${apikey}" \
-d '{"tags": [{"name": "tagName", "status": "active"}], "is_syncing": false}'
```

Now, applying this format to your specific case, the command should look something like this:

```bash
DCOM := 'cmd /c curl -X POST https://us8.api.mailchimp.com/3.0/lists/' + cListID + '/members/' + cSecure_Email + '/tags --user "anystring:' + cApi + '" -d "{""tags"": [{""name"": ""' + aTags + '"", ""status"": ""active""}], ""is_syncing"": false}" > clogrooms.txt'
```

In this command, `cListID` should be replaced with your MailChimp list ID, `cSecure_Email` should be the subscriber's hashed email address, `cApi` is your API key, and `aTags` is the tag name you want to add. Note that we need to escape double quotes inside the JSON data by using `""`.

Make sure that `aTags` is properly formatted. If `aTags` is a variable containing the tag name, ensure that it doesn't have spaces or special characters that might break the JSON format.

If you have multiple tags to add, you would expand the `tags` array like so:

```json
"tags": [{"name": "tagName1", "status": "active"}, {"name": "tagName2", "status": "active"}]
```

Lastly, ensure that the email address is correctly hashed as per Mailchimp's requirements (using MD5 and in lowercase) when replacing `cSecure_Email`. If there are still issues, double-check the JSON payload for correct formatting and ensure that all required fields are provided accurately.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to include hbCurl?

Postby Marc Venken » Wed Mar 20, 2024 1:22 pm

I went in conversation with ChatGPT )))) I have to say... that guy has patience :D :D

But we didn't get the solution.

Last try was this :

Code: Select all  Expand view

*** Hard coded test tag)
   cTagName := "tag1"   // De naam van de tag
   cTagStatus := "active"  // De status van de tag

*** Constructie JSON-payload met de enkele tag

cJsonPayload := '"tags": { "name": "' + cTagName + '", "status": "' + cTagStatus + '" } , "is_syncing": false '

msginfo(cJsonPayload)

DCOM := 'cmd /c curl -sS https://us8.api.mailchimp.com/3.0/lists/' + cLists + '/members/' + cSecure_Email + '/tags --user anystring:' + cApi + ' -d ' + CHR(34) + cJsonPayload + CHR(34) + ' > clogrooms.txt'

 


Your request doesn't appear to be valid JSON:
Parse error on line 1:
tags: { name: tag1,
^
Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: How to include hbCurl?

Postby Otto » Wed Mar 20, 2024 3:40 pm

Marc,
I think you need
tags: { name: "tag1",
Best regards,
Otto

Not tested:
Code: Select all  Expand view


cresponse  := "["
cresponse  += "{" + '"name":'   + '"' + 'name default'      + '",'
cresponse  += '"CurlPath":'         +  '"' + h['CurlPath']      + '",'
cresponse  += '"test":'             +  '"' + 'test' + '" },'
cresponse := left( cresponse , len( cresponse )-1 ) + "]"
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests