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

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)
{
//HOW DO I DO THIS?
}
curl_easy_cleanup(curl);



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:

http://curl.haxx.se/libcurl/c/libcurl-tutorial.html

Share on other sites
Thanks, this cleared alot up... I'll do that now.

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 likemyxmlstream = 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>"