[Prev][Next][Index][Thread]

Re: libwww AND NT, getting a html-doc into memory-buffer



At 01:22 PM 10/23/96 -0000, Martin Ostrowski wrote:
>I've coded this small routine ;-), to load a document from the www in the
memory-buffer (to parse it later...), but it does'nt work !

I have just tried a small variant of the chunk.c program which is one of
the Library examples in "WWW/Library/Examples". The program is included
below. Would you please try this and see if it is better? The only place
where the chunk may not be set is in HTStreamToChunk. Maybe your compiler
reacts different to line 120:

	me->chunk = *chunk =...

Henrik
#include "WWWLib.h"
#include "WWWHTTP.h"
#include "WWWInit.h"

int main (int argc, char ** argv)
{
    HTRequest * request = HTRequest_new();
    HTChunk * chunk = NULL;
    char * url = argc==2 ? argv[1] : NULL;

    /* Initialize libwww core */
    HTProfile_newPreemptiveClient("TestApp", "1.0");

    /* Turn on TRACE so we can see what is going on */
#if 0
    WWWTRACE = SHOW_CORE_TRACE + SHOW_STREAM_TRACE + SHOW_PROTOCOL_TRACE;
#endif

    /* Set up the request and pass it to the Library */
    HTRequest_setOutputFormat(request, WWW_SOURCE);
    if (url) {
	char * cwd = HTGetCurrentDirectoryURL();
	char * absolute_url = HTParse(url, cwd, PARSE_ALL);
	chunk = HTLoadToChunk(absolute_url, request);
	HT_FREE(absolute_url);
	HT_FREE(cwd);

	/* If chunk != NULL then we have the data */
	if (chunk) {
	    char * string = HTChunk_toCString(chunk);
	    printf("%s", string ? string : "no text");
	    HT_FREE(string);
	}
    } else {
	printf("Type the URL you want to accces on the command line\n");
    }

    /* Clean up the request */
    HTRequest_delete(request);

    /* Terminate the Library */
    HTProfile_delete();
    return 0;
}