- From: Duprey, John <John.Duprey@westgroup.com>
- Date: Fri, 19 Apr 2002 13:51:02 -0500
- To: "'yongjin_cho'" <yongjin_cho@zionex.com>, www-lib@w3.org
- Message-ID: <F73124AFD4114740AB4F48F9D2807C8D012ADA3F@ro-msgmbx-03>
Thank you very much! That works! -----Original Message----- From: yongjin_cho [mailto:yongjin_cho@zionex.com] Sent: Friday, April 19, 2002 3:29 AM To: www-lib@w3.org Subject: Re: Post document data and getting the results back into a string. 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 14:51:47 UTC