Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libcurl get JSON string

I'm sorry for my simple question but I'm new using libcurl. I have the following code:

    curl_easy_setopt(curl, CURLOPT_URL, "http://mypage.com/index.php?DataSourceId=1");

    curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);

    res = curl_easy_perform(curl);

Everything works fine, so when curl_easy_perform(curl) is executed I get the JSON string in the console and I want to get this string in a variable.

Please anyone can help me ?

Any suggestion would be appreciated.

like image 685
user1312508 Avatar asked May 03 '13 10:05

user1312508


People also ask

How to get JSON output from Curl?

To get JSON with Curl, you need to make an HTTP GET request and provide the Accept: application/json request header. The application/json request header is passed to the server with the curl -H command-line option and tells the server that the client is expecting JSON in response.

How to use Curl JSON?

To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.

How do I read a JSON file in CPP?

Reading data from a JSON file In the following program, we first make a root of the property tree type and load the JSON file into it. Then, we use the declare variables roll, name, class1 to store the values of “roll no”, “name” and “class” respectively. Thereafter, we display all the values.

What is Curl_easy_setopt?

curl_easy_setopt is used to tell libcurl how to behave. By setting the appropriate options, the application can change libcurl's behavior. All options are set with an option followed by a parameter.


1 Answers

You need to ask libcurl to write directly into your own memory buffer via the CURLOPT_WRITEDATA option.

Please refer to the getinmemory example that precisely illustrates how to do that.

like image 137
deltheil Avatar answered Oct 17 '22 00:10

deltheil