[Prev][Next][Index][Thread]

Re: saving a URL



Sacha sent the following reply to my question about modifying the third
example in the `Getting Started' section of the manual.
------- start of forwarded message (RFC 934 encapsulation) -------
From: sacha@clip.dia.fi.upm.es (Sacha)
To: jimg@dcz.cvo.oneworld.com
Subject: libwww & writing to a file
Date: Sun, 19 May 1996 16:19:47 +0200


Hi James,

I'm also a newbie with the whole libwww thing... here's what I
did to solve your problem (how to get example #3 to stop prompting
and write to a file instead):


#include "WWWLib.h"
#include "WWWHTTP.h"
#include "WWWMIME.h"
#include "WWWApp.h"

int main (int argc, char ** argv)
{
  FILE* s; 
  
  HTList * converters = HTList_new();
  HTRequest * request = HTRequest_new();   /* Create a request object */

  HTLibInit("TestApp", "1.0");

  HTProtocol_add("http", YES, HTLoadHTTP, NULL);
  
  HTConversion_add(converters,
		   "text/x-http",
		   "*/*",
		   HTTPStatus_new,
		   1.0, 0.0, 0.0);

  HTConversion_add(converters,
		   "message/rfc822",
		   "*/*", 
		   HTMIMEConvert,
		   1.0, 0.0, 0.0);
  
  HTFormat_setConversion(converters);
  

  /* before I added this next line it wouldn't write */
  HTRequest_setOutputFormat(request, WWW_SOURCE);
  
  if (!(s = fopen("bar", "wb"))) {
    printf("maybe not\n");
    exit(0);
  }
  
  HTRequest_setOutputStream(request, HTFWriter_new(request, s, YES));
  
  HTLoadAbsolute(argv[1], request);
  
  
  /*
     HTAlert_add(HTPrompt, HT_A_PROMPT);
     if (argc == 2) {
       HTLoadAbsolute(argv[1], request);
     } else
       printf("Type the URL to fetch\n");
  */
  
  HTRequest_delete(request);			/* Delete the request object */
  HTConversion_deleteAll(converters);
  HTLibTerminate();
  return 0;
}


Enjoy. Maybe you want to post it to the list...

See you,

Sacha.
------- end -------


Follow-Ups: