RE: Store the result of GET in a file

"Adam Mlodzinski" <[email protected]> Tue, 9 May 2006 12:36:54 -0400
Newsgroups gmane.comp.lib.libwww
Message-ID <46C5DCD410224A42BE3151AC8AE75E4E07D75371@tormbxw01.prod.quest.corp>
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.

--=20
Adam Mlodzinski


----Original Message----
From: [email protected] [mailto:[email protected]]
On Behalf Of [email protected]
Sent: Tuesday, May 09, 2006 4:35 AM
To: [email protected]
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:
>=20
> //Store Groups in a Text file //
> #include <w3c-libwww/WWWLib.h>
> #include <w3c-libwww/WWWHTTP.h>
> #include <w3c-libwww/WWWInit.h>
>=20
> PRIVATE int printer (const char * fmt, va_list pArgs) {
>     return (vfprintf(stdout, fmt, pArgs)); }
>=20
> 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;
> }
>=20
> int main (int argc, char ** argv)
> {
>     HTRequest * request =3D HTRequest_new();
>     char * url =3D
> "http://mail.persistent.co.in/cgi-bin/addrbook.cgi/xab/v1/get_
groups.xml?sessionid=3D1c2200f500f5e60bf2d9f77b0f8c684e4&group=3D*";
> 	char *filename=3D"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)=3D=3DYES)
> 		printf("Loaded in file");
> 	else
> 		printf("Could not load");
> 	HT_FREE(cwd);
>     HTRequest_delete(request);
>     HTProfile_delete();
>     return 0;
> }
>=20
>=20
> I am getting a zero length file. Please guide.