- From: Henrik Kim Berle <hkb@terma.com>
- Date: Fri, 11 Sep 1998 16:41:43 +0200
- To: www-lib@w3.org
- Message-ID: <199809111441.QAA19902@oklahoma.terma.com>
Hello, I am trying to make a small program using libwww-5.1m which is able to post a few values to a server and then save the result in a file. basically the same example as the example : w3c-libwww-5.1m/Library/Example/LoadToFile.c Just using the POST method. Could one of you please tell me what I am doing wrong. Thanks alot, Henrik +-----------------------------------+----------------------------+ |Henrik K. Berle | Email : hkb@terma.com | |TERMA Elektronik AS | Voice : +45 45949400 | |Bregneroedvej 144 | Fax : +45 45949699 | |DK-3460 Birkeroed, Denmark | Direct: +45 45949679 | +-----------------------------------+----------------------------+
#include "WWWLib.h" /* Global Library Include file */
#include "WWWMIME.h" /* MIME parser/generator */
#include "WWWNews.h" /* News access module */
#include "WWWHTTP.h" /* HTTP access module */
#include "WWWFTP.h"
#include "WWWFile.h"
#include "WWWGophe.h"
#include "WWWInit.h"
#ifdef LIBWWW_SHARED
#include "HTextImp.h"
#endif
#define APP_NAME "GETTOOL"
#define APP_VERSION "1.0"
#define DEFAULT_OUTPUT_FILE "get.out"
/*
** We get called here from the event loop when we are done
** loading. Here we terminate the program as we have nothing
** better to do.
*/
int terminate_handler (HTRequest * request, HTResponse * response,
void * param, int status)
{
/* Delete our request again */
HTRequest_delete(request);
/* Delete our profile */
HTProfile_delete();
exit(status ? status : 0);
}
int main (int argc, char ** argv)
{
int status = 0;
int arg = 0;
char * outputfile = NULL;
char * getme = NULL;
HTRequest * request = NULL;
HTChunk * chunk = NULL;
HTParentAnchor * anchor = NULL;
HTAssocList * formdata = NULL;
HTStream * target;
FILE *fp = NULL;
/* Initiate W3C Reference Library with a client profile */
HTProfile_newNoCacheClient(APP_NAME, APP_VERSION);
/* Add our own filter to terminate the application */
HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
/* Turn off any interactions */
HTAlert_setInteractive(NO);
/* Scan command line for parameters */
for (arg=1; arg<argc; arg++) {
if (!strcmp(argv[arg], "-o")) {
outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
argv[++arg] : DEFAULT_OUTPUT_FILE;
} else {
getme = argv[arg];
}
}
/* Make sure we have an output */
if (!outputfile) outputfile = DEFAULT_OUTPUT_FILE;
if (getme && *getme) {
request = HTRequest_new();
/* Start the load */
/* status = HTLoadToFile(getme, request, outputfile); */
formdata = HTAssocList_new ();
HTAssocList_addObject (formdata, "name", "value");
/* If replace then open the file */
if ((fp = fopen(outputfile, "wb")) == NULL) {
HTRequest_addError(request, ERR_NON_FATAL, NO, HTERR_NO_FILE,
(char *) outputfile, strlen(outputfile),
"LoadToFile");
return -1;
}
/* Set the output stream and start the request */
HTRequest_setOutputFormat(request, WWW_SOURCE);
HTRequest_setOutputStream(request, HTFWriter_new(request, fp, NO));
anchor = HTPostFormAbsolute (formdata,
getme,
request);
/* Go into the event loop... */
HTEventList_loop(request);
} else {
/* Delete our profile if no load */
HTProfile_delete();
}
return 0;
}
Received on Friday, 11 September 1998 10:41:36 UTC