Re: Post Anchor to Chunk?

Hi Timo,

Thanks for your advise!

Based on HTPostFormAnchorToChunk() and
HTPostFormAnchor(), I created two functions(see
below) to post arbitrary data, now I can send
request to server properly, the returning chunk I
get however, is always empty. If I plug-in a HTXML
callback with the built-in xml parser, I can see
the correct reply data are sent back, so I know
the reply data are somewhere but I just can't get
them in one chunk.

The two functions look pretty simple to me, but
there must be something I missed. I really
appreciate any help!!


/*	Send an arbitrary doc request using POST from an
anchor
**	---------------------------------------------
**	Request a document referencd by an anchor object
appended with the
**	docbuf given.
*/
PUBLIC HTParentAnchor * HTPostDocAnchor (char *
docbuf,
                                         HTFormat
form,
                                         HTAnchor *
anchor,
                                         HTRequest * 
request)
{
    HTParentAnchor * postanchor = NULL;
    if (docbuf && anchor && request) {
        HTUserProfile * up =
HTRequest_userProfile(request);
        char * tmpfile =
HTGetTmpFileName(HTUserProfile_tmp(up));
        char * tmpurl = HTParse(tmpfile, "file:",
PARSE_ALL);
        if (docbuf) {
            /*
            **  Now create a new anchor for the post
data and set up
            **  the rest of the metainformation we
know about this anchor. The
            **  tmp anchor may actually already exist
from previous postings.
            */
            postanchor = (HTParentAnchor *)
HTAnchor_findAddress(tmpurl);
            HTAnchor_clearHeader(postanchor);
            HTAnchor_setDocument(postanchor, docbuf);
            HTAnchor_setLength(postanchor,
strlen(docbuf));
            HTAnchor_setFormat(postanchor, form);

            /*
            **  Bind the temporary anchor to the
anchor that will contain the
            **  response
            */
            HTLink_removeAll((HTAnchor *) postanchor);
            HTLink_add((HTAnchor *) postanchor,
(HTAnchor *) anchor,
                       NULL, METHOD_POST);

            /* Set up the request object */
            HTRequest_addGnHd(request, HT_G_DATE);	 /*
Send date header */
            HTRequest_setAnchor(request, anchor);
            HTRequest_setEntityAnchor(request,
postanchor);
            HTRequest_setMethod(request, METHOD_POST);

            /* Add the post callback function to
provide the data */
            HTRequest_setPostCallback(request,
HTEntity_callback);

            /* Now start the load normally */
            launch_request(request, NO);
            fprintf(stderr, "request launched\n");
        }
        HT_FREE(tmpfile);
        HT_FREE(tmpurl);
    }
    return postanchor;
}

/*
**	POST a URL and save the response in a mem buffer
**	------------------------------------------------
**	Returns chunk if OK - else NULL
*/
PUBLIC HTChunk * HTPostDocAnchorToChunk (char *
docbuf,
                                         HTFormat
format,
                                         HTAnchor *
anchor,
                                         HTRequest *
request)
{
    if (docbuf && anchor && request) {
        HTChunk * chunk = NULL;
        HTStream * target = HTStreamToChunk(request,
&chunk, 0);
        HTRequest_setOutputStream(request, target);
        fprintf(stderr, "ok to postdoc\n");
        if (HTPostDocAnchor(docbuf, format, anchor,
request) != NULL) {
            fprintf(stderr, "postdoc returned ok\n");
            return chunk;
        }
        else {
            fprintf(stderr, "postdoc returned
null\n");
            HTChunk_delete(chunk);
            return NULL;
        }
    }
    return NULL;
}


--- Timo.Ross@ic3s.de wrote:

> Hi Kevin!

> I think I understand your problem (-;
> I think there is no complete function in LIBWWW that
match on you problem
> or I do not know this function, but there is always
a way.
> Please have a look to the souce code of the HTAccess
module (HTAccess.c).
> There you will find the source of the
"HTPostFormAnchorToChunk" function.
> This function calls the "HTPostFormAnchor" function.
In this function you
> can see, what has to be done for a post. There you
can modify the parameter
> of "HTAnchor_setDocument(postanchor, form_encoded);"
and
> "HTAnchor_setFormat(postanchor, WWW_FORM);"
functions to your demands.

> Hope this will help you ?!

> Timo!

__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/

Received on Tuesday, 19 September 2000 18:17:39 UTC