Why isn't libcurl doing anything?
from Irelephant@lemm.ee to programming@programming.dev on 29 Nov 20:13
https://lemm.ee/post/48605874
from Irelephant@lemm.ee to programming@programming.dev on 29 Nov 20:13
https://lemm.ee/post/48605874
I have tried googling, and found no solution to my problem. I’m trying to learn how to use libcurl, a c networking library. I tried compiling a program that was automatically generated from curl, and a few examples i found online but nothing happened. I got no errors or logs, the program stopped “sucessfully” but i get no output. I also cant write to the console either while the library is included.
Any help is appreciated.
threaded - newest
There’s no way to even attempt to answer your question without the actual code
You’re right, but it doesn’t do anything, no matter what the code is, so I assumed that I needn’t include it. Kinda stupid of me. In any case, here it is:
Another piece of code i tried was:
This makes it sound like your code is doing what you’re telling it to do with no errors. Show us your code and we can help figure out the delta between expectation and reality.
You’re right, but it doesn’t do anything, no matter what the code is, so I assumed that I needn’t include it. Kinda stupid of me. In any case, here it is:
Another piece of code i tried was:
Unless I’m mistaken, that first example as-written will
fetchPOST the network resource and then immediately clean up. The fact that CURLOPT_NOPROGRESS is passed means that the typical progress bar forcurl
in an interactive shell will be suppressed. The comment in the code even says that to make the example do something useful, you’ll have to pass callback pointers, possibly by way of CURLOPT_WRITEFUNCTION or CURLOPT_WRITEDATA.From the
curl_easy_perform()
man page:Ah, right.
Finished it, i think. Still does “nothing”
edit: probably shouldn’t include my api key with it.
I’m on mobile so I can’t compile this myself, but can you clarify on what you’re observing? Does “nothing” mean no output to stdout and stderr? Or that you did get an error message but it’s not dispositive as to what libcurl was doing? Presumably the next step would be to validate that the program is executing at all, either with a debugger or printf-style debug statements at all junctures.
Please include as much detail as you can, since this is now more akin to a bug report.
EDIT: wait a sec. What exactly is this example code meant to do? The Pastebin API call suggests that this is meant to upload a payload to the web, not pull it down. But CURLOPT_WRITEFUNCTION is for receiving data from a URI. What is your intention with running this example program?
I’m trying to send a post request to Pastebins api to make a paste. This is one of the first programs I have tried to write with libcurl, so its probably wrong.
What exactly are you expecting to happen? Have you written code before?
I have written code before. I just started with C recently. I am expecting it to do literally anything at this point, but for some reason whenever I use the libcurl library literally nothing happens that i can observe.
As a sanity check, does this work?
That should write a file called output.data with the HTML from www.wikipedia.org and print out the number of bytes each time the write callback receives data for processing.
On my machine, it prints the following when it works successfully (byte counts may vary for you):
If I change the URL to nonsense instead to make it fail, it prints text like this on my system:
Its not working unfortunatly.
Does hello world work? You should’ve gotten at least some console output.
That works perfectly
Try adding some prints to stderr through my earlier test program then and see if you can find where it stops giving you output. Does output work before
curl_easy_init
? After it? Somewhere later on?Note that I did update the program to add the line with
CURLOPT_ERRORBUFFER
– that’s not strictly needed, but might provide more debug info if something goes wrong later in the program. (Forgot to add the setup line initially despite writing the rest of it… 🤦♂️️)You could also try adding
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
to get it to explain more details about what it’s doing internally if you can get it to print output at all.Does your Antivirus or Firewall prevents it from accessing the internet maybe?
I checked, and it doesn’t.