Libcurl GET POST parameters

libcurl
Clarion6.3
Example HTTPWebServices.app

Url field : Send:Url
Parameters field : Send:PostParams
CustomRequest field : Send:CustomRequest

res = curl.SendRequest(Send:Url, Send:PostParams, respBuffer)

I need to test API on GEt and POST requests:

1 GET . curl --location --request GET ‘https://myspotlight.app/api/int/user-info?apikey=SL12345&P_BARKOD=00750000000011
–data-raw ‘’

CALL : https://server.app/api/int/user-info?apikey=SL12345&P_BARKOD=00750000000011

When I put above call in Send:Url field (Send:CustomRequest = GET) , I get right response from server .

When tried to separate above string :
Send:Url : https://server.app/api/int/user-info
Send:PostParams : apikey=SL12345&P_BARKOD=00750000000011 ,

I get error , apikey field is mandatory

2 POST . curl --location --request POST ‘https://server.app/api/int/insert-transaction-v2
–data-raw ‘{
“apikey”: “SL-12345”,
“p_id”: “105”,
“p_orgjed”: “10”,
“p_pan”: “00750000000011”,
“p_user_id”: “100”,
“p_iznos_racuna”: 50,
“p_iznos_bez_ak”: 0,
“p_iznos_placen_bp”: 1,
“p_iznos_placen_pp”: 5,
“p_komentar”: “”,
“stavke”: [
{
“rbr”: 1,
“artikal”: “14”,
“kolicina”: 1,
“popust”: 0,
“iznosMP”: 50
}
],
“vauceri”: { “1”:{“kod”:“000001002005978451”} }
}’

I create file (datafile ) from content of --data-raw ’ { … } ’ , and tried with command :

res = curl.SendFile(Send:Url, clip(datafile), Send:PostParams, Send:Filename)
where
Send:Url = https://server.app/api/int/insert-transaction-v2
Send:Filename=’’
Send:PostParams= POST

But, I get no response at all
I tested curl command on REQBIN , server responded.

Any help ?

  1. GET request ignores POST parameters (Send:PostParams).

  2. Why don’t you send raw data?

    Send:PostParams = ‘{{’ |
    & ‘“apikey”: “SL-12345”,’ |
    & ‘“p_id”: “105”,’ |
    & ‘“p_orgjed”: “10”,’ |
    & ‘“p_pan”: “00750000000011”,’ |
    & ‘“p_user_id”: “100”,’ |
    & ‘“p_iznos_racuna”: 50,’ |
    & ‘“p_iznos_bez_ak”: 0,’ |
    & ‘“p_iznos_placen_bp”: 1,’ |
    & ‘“p_iznos_placen_pp”: 5,’ |
    & ‘“p_komentar”: “”,’ |
    & ‘“stavke”: [’ |
    & ‘{{’ |
    & ‘“rbr”: 1,’ |
    & ‘“artikal”: “14”,’ |
    & ‘“kolicina”: 1,’ |
    & ‘“popust”: 0,’ |
    & ‘“iznosMP”: 50’ |
    & ‘}’ |
    & ‘],’ |
    & ‘“vauceri”: {{ “1”:{{“kod”:“000001002005978451”} }’ |
    & ‘}’

    curl.SetCustomRequest(‘POST’)
    curl.SendRequest(Send:Url, Send:PostParams, respBuffer)

And always inspect DebugView log, it contains many useful info and helps to find what’s going wrong.

Thanks,

it works, same response from API , as native curl call.

What is a size of Send:PostParams . I know that it has to be used as params , but is there any size limit of Send:PostParams (raw data) ?
In what cases we use curl.SendFile ?
In my case I tried
res = curl.SendFile(Send:Url, datafile, Send:PostParams, Send:Filename)
If I create datafile respecting your corrections in brackets and quotation marks , could I
use it. What is in that case Send:PostParams ?

Thanks again

Look at SendFile declaration, it doesn’t accept PostParams argument, but it expects contentType (but it can be a blank string). Actually SendFile is curl’s “–data-binary” equivalent.

AFAIK there are no limits for postparams data.

How looks libcurl call for twilio whatsapp project:

https://api.twilio.com/2010-04-01/Accounts/AC36a490581e1a6b00f075ac43c65f8728/Messages.json’ -X POST \

–data-urlencode ‘To=whatsapp:tonumber’ \

–data-urlencode ‘From=whatsapp:fromnumber’ \

–data-urlencode ‘Body=Your appointment is coming up on July 21 at 3PM’ \

-u AC36a490581e1a6b00f075ac43c65f8728:[AuthToken]

Thanks

You must url encode To, From and Body, and combine them to post parameters, something like this:

postparams = printf('To=%U&From=%U&Body=%U', var:to, var:from, var:body)
curl.Init()
curl.SetUserPwd(sid, token)
ret = curl.SendRequest(url, postparams, respfile)

I tried to put libcurl in multidll app for sending mail .
Exported procedures from 6.3 example SendMail imported in dll .
Compiling passed , but on start main exe I got an error
image

Something missed-
What has to be in datadll, dlls and in exe ?

Looks like libcurl.dll is outdated.