RE: Store the result of GET in a file

The cheesy way to do this with virtually no effort would be to enable
the "p" trace flag and rebuilding in debug mode. In other words, given:
> #if 0
>     HTSetTraceMessageMask("sop");
> #endif
change the zero to a one.

I say cheesy because the file produced is hardcoded to "w3chttp.out" (in
HTTP.c, around lines 1190-1230 or so), and it's contents are replaced
with every request. If you need or want more control over the output
file, or you don't want a debug build, have a look at the HTFWrite class
- it looks like it gives you more control over storing request output.

-- 
Adam Mlodzinski


----Original Message----
From: www-lib-request@w3.org [mailto:www-lib-request@w3.org]
On Behalf Of neelu_dhiman@persistent.co.in
Sent: Tuesday, May 09, 2006 4:35 AM
To: www-lib@w3.org
Subject: Store the result of GET in a file

> 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 Wednesday, 10 May 2006 18:28:20 UTC