Jump to content
  • Advertisement
Sign in to follow this  

libcurl and reading in data

This topic is 4443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've decided to get rid of HTTP-GET and use libcurl to send HTTP requests. It doesn't crash or cause bugs with my program. Now the problem is, how do I read in the web page? the php script I call will return (using echo();) an XML document. This contains the list of servers/games with a <server> tag. How can I take the stream of ANSI charecters and feed it into my XML reader. What function do I use in libcURL to get a char* string or something similar? Is there a differnt library needed?
CURL* curl;
CURLcode res;

curl = curl_easy_init();

curl_easy_setopt(curl, CURLOPT_URL,"www.silvernova.co.uk/thegame/server.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "action=get");

res = curl_easy_perform(curl);

if(res == CURLE_OK)
    //read in data

thanks in advanced.

Share this post

Link to post
Share on other sites
The way to do it is to use the CURLOPT_WRITEFUNCTION and CURLOPT_WRITEDATA options to let libcurl write the received data to a temporary file (or just copy to some buffer).
Specifically, look at the ftpget.c example (in the 'examples' folder in libcurl source distribution) where these 2 options are demo'ed (it's an FTP example but these options work also for http protocols).

Also read an important detail about CURLOPT_WRITEFUNCTION if you're using libcurl.dll on Windows, here:


Share this post

Link to post
Share on other sites
Just double checking...
I have a function that follows the prototype:

size_t function( void *ptr, size_t size, size_t nmemb, void *stream);

//does something like
myxmlstream = ptr;

Is it safe to have this or will libcURL delete the stream pointer after it has been used? or will it stay untouched?
also, I will get an ANSI string like this wont I? (the \n ect... not the xml content) : "<xmlhead>\n<sometag>\n</xmlhead>"

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!