Re: How to use libcurl to POST data in JSON-format

Aleksandar Lazic via curl-library <[email protected]>
Newsgroups gmane.comp.web.curl.library
Message-ID <[email protected]>
Hi.

On 2025-06-18 (Mi.) 10:47, Владислав Коробов via curl-library wrote:
> Hello everyone,
> I work on Linux #astra31+ci49-Ubuntu with  GNU/Linux.
> On my system installed curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 
> OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.7 libidn2/2.0.5 libpsl/0.20.2 
> (+libidn2/2.0.5) libssh2/1.11.0 nghttp2/1.36.0 librtmp/2.3.
>  From this system I can get the data from some device usung console request to 
> the private https server via the curl command:
> curl -k -X GET -H 'Authorization: Bearer nokey'  https://<IP-address>:<port>/ 
> api/ccu/online
> I’ve found, how to get data from this server, using libcurl calls. But I need 
> additionally to POST some data to this server using JSON-format.
> Using console request:
> curl -k -X POST -d ‘{«1»:0}’ -H ‘Content-type: application/json’ -H 
> ‘Authorization: Bearer nokey’ https://<host>:Port/api/ccu/outputs
> I can change some output registers of the device, via this server. Is it 
> possible anyhow using some options of libcurl to POST data to this device in 
> JSON-format, like it is done in the previous curl console command?

You can use the `--libcurl` parameter to create a starting .c-file as shown on 
that link.
https://everything.curl.dev/libcurl/--libcurl.html?highlight=--libcur#--libcurl

Small suggestion about `-X` usage.
https://daniel.haxx.se/blog/2015/09/11/unnecessary-use-of-curl-x/

> Thanks in advance!
> --
> Vladislav Korobov
> --
> Владислав Коробов
> Отправлено из Почты Mail <https://trk.mail.ru/c/zzm979>

Regards
Aleks
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.