From the course: Code Clinic: C++

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

HTTP request using libcurl

HTTP request using libcurl - C++ Tutorial

From the course: Code Clinic: C++

Start my 1-month free trial

HTTP request using libcurl

- [Instructor] To handle sending the HTT post request to the Google Geolocation API server, and handling the response, I turned to libcurl which is a popular library for handling a wide variety of file transfer protocols in C or C++ My code to handle the HTT post request is found in the get location member function within the Geolocation request class. Beginning at line nine, you can see that the function takes formatted jsonPayLoad string as an input. From there, I initialized the curl session on lines 12 and 13. They'll work to build the message. At lines 20 and 21, I configured the message headers to indicate I'm sending json content. Then at lines 24 through 26, I allocate an empty memory structure which will be used to hold the response. Lines 29 through 35 configure a number of curl options including the URL, request type, headers and json payload contents. Lines 34 and 35 configure a callback function which is…

Contents