libcurl examples
Home › Forums › MultiConnect OCG › libcurl examples
- This topic has 7 replies, 4 voices, and was last updated 10 years, 8 months ago by Jesse Gilles.
-
AuthorPosts
-
March 18, 2014 at 9:47 am #5577Greg LudewigParticipant
I’m trying to write a C application that uses libcurl to submit HTTP POST, PUT, and GET requests, and I was wondering if there are any examples available of how to use libcurl in the CoreCDP environment. The requests I want to send are fairly complex, and I’m having trouble figuring out how to use the various libcurl functions to generate the requests I want.
I can generate a curl string and submit it via the system() call, and my requests work, but there doesn’t seem to be a way to capture the curl output (such as the HTTP response code) in that case. It looks like using libcurl will allow me to capture the response code, but as I said, I’m having trouble understanding how to generate the proper request. Are there any examples avaiable of how to use libcurl, or of how to capture the output if I submit a curl command directly using the system() call.
Below is an example of a curl request I need to generate and submit:
curl -X POST -v -H Content-Type:application/json -d ‘{“id”:{“mn”: “ammptest”,”sn”: “ammptestvunder3″},”pingRate”: 15}’ $’http://minnetronix-sandbox-connect.axeda.com/ammp/assets/1′
March 18, 2014 at 10:46 am #5588Darrik SpaudeKeymasterHi Greg,
There were 4 topic submissions that were flagged as spam. Do you want the content of this one modified since it is a public forum?
March 18, 2014 at 11:07 am #5590Greg LudewigParticipantDarrik,
Thanks for the response. I’m not sure why they were flagged as spam, but I submitted the same post multiple times because it never seemed to show up on the list of forum topics after I submitted it. I’m OK with this post as is, if someone could help me with some libcurl examples, that would be great.
Greg
March 19, 2014 at 9:28 am #5593Bryan TranModeratorHi Greg,
To capture the output of a curl command directly using the system() call, you could try this: curl -vs google.com > myfile 2>&1
This will redirect the output/error of the curl command to: myfile.
Notes: Should be written into a directory one of the mounted tmpfs (in RAM) filesystems or to a removable SD card.
Thanks,
BT
March 19, 2014 at 2:36 pm #5597Greg LudewigParticipantThanks Bryan, that seems to do the trick.
I do have a couple of questions, though.
1) Why do I need to write the output to the RAM filesystem or the SD card? It seems to work OK if I use the main filesystem.
2) I can’t find any documentation on how to access/use the RAM filesystem. Is it simply the filesystem at /mnt/ram (which appears to be linked to /media/ram)?Thanks again.
Greg
March 19, 2014 at 2:54 pm #5598Bryan TranModeratorHi Greg,
1. If your application is not write to the flash on a regular basis, then it is ok to write to main file system. However, if it is writing on regular basis, then it should be in RAM file system. This is so that you don’t wear out the flash.
2. It is simply the file system at /media/ram. You can just create file in that folder.
Notes: If the device is reset, then all the files that you created there will be lost.
Regards,
BT
March 20, 2014 at 4:48 pm #5610Greg LudewigParticipantBryan,
Thanks, that makes sense. I will use the RAM file system. That brings up another question for me, though. What about the system log file (/var/log/messages)? Is it in flash, so that I should avoid writing to the log on a regular basis?
Greg
March 20, 2014 at 4:53 pm #5611Jesse GillesBlockedGreg,
There are multiple RAM-based filesystems on the unit by default. If you run ‘mount’ you can look for filesystems of type ‘tmpfs’.
You will find that /var/volatile is also a tmpfs and if you run ‘ls -l’ in /var, you will see that /var/log is a soft link to /var/volatile/log. So /var/log is actually in the tmpfs and therefore in RAM.
Jesse
-
AuthorPosts
- You must be logged in to reply to this topic.