W3C home > Mailing lists > Public > www-lib@w3.org > April to June 2006

Store the result of GET in a file

From: <neelu_dhiman@persistent.co.in>
Date: Tue, 9 May 2006 14:04:43 +0530 (IST)
To: www-lib@w3.org
Message-Id: <20060509140443.AJF43158@mail6.persistent.co.in>

Hi friends,
I am passing an http GET request using libwww. The output of
the request is an XML file that I want to dump to some text
file. Here is the code:

//Store Groups in a Text file //
#include <w3c-libwww/WWWLib.h>
#include <w3c-libwww/WWWHTTP.h>
#include <w3c-libwww/WWWInit.h>

PRIVATE int printer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stdout, fmt, pArgs));
}

PRIVATE int tracer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stderr, fmt, pArgs));
}
PRIVATE int terminate_handler (HTRequest * request, HTResponse
* response, void * param, int status) 
{
    /* Check for status */
    HTPrint("Load resulted in status %d\n", status);
		/* we're not handling other requests */
	HTEventList_stopLoop (); 
	/* stop here */
    return HT_ERROR;
}

int main (int argc, char ** argv)
{
    HTRequest * request = HTRequest_new();
    char * url =
"http://mail.persistent.co.in/cgi-bin/addrbook.cgi/xab/v1/get_groups.xml?sessionid=1c2200f500f5e60bf2d9f77b0f8c684e4&group=*";
	char *filename="Groups";
  HTProfile_newPreemptiveClient("TestApp", "1.1");
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);
#if 0
    HTSetTraceMessageMask("sop");
#endif
    HTRequest_setOutputFormat(request, WWW_RAW);
    HTRequest_addConnection(request, "close", "");
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL,
HT_FILTER_LAST);
	if ( HTLoadToFile (url, request,filename)==YES)
		printf("Loaded in file");
	else
		printf("Could not load");	
	HT_FREE(cwd);
    HTRequest_delete(request);
    HTProfile_delete();
    return 0;
}


I am getting a zero length file. Please guide.
Received on Tuesday, 9 May 2006 08:38:40 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:45 GMT