- From: Jerry G. Chiuan <jerry@oridus.com>
- Date: Thu, 28 Aug 2003 21:35:41 -0700
- To: <www-lib@w3.org>
Hi All,
I am trying to use the same mechanism shown in this example to POST data to
the HTTP server and save the result in a chunk
http://www.w3.org/Library/Examples/postform.c
As I know, the program goes into the event loop to wait for the response
after calling HTPostFormAnchorToChunk( )
then, terminate_handler would be invoked once the response is received (or
timeout occurs)
However, I would like to handle the response in terminate_handler, return
from terminate_handler to back main( ), then keep doing something else
after this line HTEventList_loop(request).
Or, I just simply want to wait for the response in the event loop, then do
something to handle response afterwards ( don't invoke terminate_handler )
is it possible? if yes, how shall I do?
ps: please refer to the sample code below
Regds,
- Jerry
PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
void * param, int status)
{
if (status == HT_LOADED && result && HTChunk_data(result)) {
HTPrint("%s", HTChunk_data(result));
HTChunk_delete(result);
}
/* We are done with this request */
HTRequest_delete(request);
/* Terminate libwww */
HTProfile_delete();
exit(0);
}
int main (int argc, char ** argv)
{
:::
:::
/* 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);
:::
:::
/* Create a request */
request = HTRequest_new();
/* Set the default output to "asis" */
HTRequest_setOutputFormat(request, WWW_SOURCE);
/* Get an anchor object for the URI */
anchor = HTAnchor_findAddress(uri);
/* Post the data and get the result in a chunk */
result = HTPostFormAnchorToChunk(formfields, anchor, request);
/* Clean up the form fields */
HTAssocList_delete(formfields);
/* Go into the event loop... */
HTEventList_loop(request);
return 0;
}
Received on Friday, 29 August 2003 00:33:20 UTC