Question

I've been recently writing a program that I will want to request and receive information from URLs. For example: http://www.example.com/getRecords.asp?name=Jack&surname=Jackson

If that website responded by printing exists=true or exists=false

It would display on the terminal The user exists! or The user does not exist!

Also, it would be good if the person using the program could type in the variables themselves, e.g Name to check: Chuck Surname to check: Norris http://www.example.com/getRecords.asp?name=Chuck&surname=Norris

But there's another thing, if for example the test returns true, the website also says exists=true&age=30 It would be good to be able to print this other variable on the screen or even save it to a file.

If you can help please answer down below, or send me a link to an understandable tutorial on how to use libcurl. Thanks.

EDIT: Thank you for your answers! I have also figured out the variable part on my own.

Était-ce utile?

La solution

I believe you should take a look to this sample code from the libcurl Example source codes :

sepheaders.c

Then change the URL

curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");

and implement your own logic in :

static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)

Then you may want to save the server answer in a std::string :

curl WRITEFUNCTION and classes

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top