- From: yongjin_cho <yongjin_cho@zionex.com>
- Date: Fri, 19 Apr 2002 03:01:01 -0400 (EDT)
- To: <www-lib@w3.org>
- Message-ID: <000601c1e770$3c6d6440$4201a8c0@kino>
hi !
I can get the response string into a chunk by this..
It comes from post.c, postform.c in examples.
 I've just modified that.
If u see terminate_handler callback function, u will know how it works.
======================
#include "WWWLib.h"
#include "WWWInit.h"
HTChunk * chunk = NULL;
PUBLIC HTChunk * PostAnchorToChunk (HTParentAnchor *    source,
                         HTAnchor *             destination,
                         HTRequest *            request)
{
    if (source && destination && request) {
        HTChunk * chunk = NULL;
        HTStream * target = HTStreamToChunk(request, &chunk, 0);
        HTRequest_setOutputStream(request, target);
        if (HTPostAnchor(source, destination, request) != NULL)
            return chunk;
        else {
            HTChunk_delete(chunk);
            return NULL;
        }
    }
    return NULL;
}
PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
                               void * param, int status)
{
    char * string;
    string = HTChunk_toCString(chunk);
    printf("string : %s\n", string);
    HT_FREE(string);
    /* We are done with this request */
    HTRequest_delete(request);
    /* Terminate libwww */
    HTProfile_delete();
    
    exit(0);
}
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTParentAnchor * src = NULL;
    HTAnchor * dst = NULL;
    char * dst_str = NULL;
    char * data = NULL;
    /* Create a new premptive client */
    HTProfile_newNoCacheClient("libwww-POST", "1.0");
    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
    /* Set the timeout for long we are going to wait for a response */
    HTHost_setEventTimeout(20000);
    /* Handle command line args */
    if (argc >= 3) {
        dst_str = argv[1];
        data = argv[2];
    }
    else
        return -1;
    if (data && *data && dst_str && *dst_str)
    {
        request = HTRequest_new();
        HTRequest_setOutputFormat(request, WWW_RAW);
        dst = HTAnchor_findAddress(dst_str);
        src = HTTmpAnchor(NULL);
        HTAnchor_setDocument(src, data);
        HTAnchor_setLength(src, strlen(data));
        chunk = PostAnchorToChunk(src, dst, request);
        HTEventList_loop(request);
    }
    return 0;
}    
Received on Friday, 19 April 2002 03:38:07 UTC