- From: Christian Rütgers <chr@1komma6.com>
- Date: Sun, 05 Sep 1999 16:59:33 +0200
- To: "www-lib@w3.org" <www-lib@w3.org>
Hi,
I've asked two weeks ago the following question. Is there someone able
to get me an answer or tell me a resource to get a solution?
I try to get the response code from a server and, when getting a
redirect-error, the redirection adress. I've made a program, based on a
code-snippet on this list, to get the approbiate information. I do not
want to use any terminate_handler.
I attach my code. Any help?
filename="libwww_test.c"
#include <wwwconf.h>
#include <WWWLib.h>
#include <WWWHTTP.h>
#include <WWWInit.h>
/* Name and version of the program. */
#define PROG_NAME       "urlbot"
#define PROG_VERS       "1.0"
PRIVATE HTErrorMessage HTErrors[HTERR_ELEMENTS] =
{HTERR_ENGLISH_INITIALIZER};
int 
main (int argc, char *argv[])
{
  HTList *pr_converters = NULL;
  HTList *pr_transfer_encodings = NULL;
  HTList *pr_content_encodings = NULL;
  HTRequest *pr_request = NULL;
  char *pc_cwd = NULL;
  char *pc_absolute_url = NULL;
  HTAnchor * dst = NULL;
  HTList *pr_list = NULL;
  int err_code = 0;
  HTLibInit (PROG_NAME, PROG_VERS);
  HTAlertInit ();
  HTAlert_setInteractive (NO);
  pr_converters = HTList_new ();
  pr_transfer_encodings = HTList_new ();
  pr_content_encodings = HTList_new ();
  HTTransportInit ();
  HTProtocolInit ();
  HTBind_init ();
  HTNet_setMaxSocket (32);
  HTNetInit ();
  HTAAInit ();
  HTProxy_getEnvVar ();
  HTHost_setEventTimeout (30000);
  HTConverterInit (pr_converters);
  HTFormat_setConversion (pr_converters);
  HTTransferEncoderInit (pr_transfer_encodings);
  HTFileInit ();
  /* Set up the basic request structure.  */
  pr_request = HTRequest_new ();
  HTRequest_setGnHd (pr_request, 0);
  HTRequest_setRqHd (pr_request, HT_C_HOST + HT_C_USER_AGENT);
  HTRequest_setRsHd (pr_request, 0);
  HTRequest_setEnHd (pr_request, 0);
  HTRequest_setMethod (pr_request, METHOD_GET);
  HTRequest_setOutputFormat (pr_request, WWW_SOURCE);
  HTRequest_setPreemptive (pr_request, YES);
        /* Get an anchor object for the destination URI */
        dst = HTAnchor_findAddress(argv[1]);
        /* POST the source to the dest */
        HTHeadAnchor(dst, pr_request);
// HTHeadAbsolute (argv[1], pr_request);
        {
                char * addr = HTAnchor_address((HTAnchor *)
HTRequest_anchor(pr_request));
                char * re_addr =
HTAnchor_address(HTResponse_redirection(HTRequest_response
(pr_request)));
                HTPrint("The address `%s\' was redirected to `%s\'\n",
addr, re_addr ? re_addr : "<none>");
        }       
  /*
     ** Get the error code of the request.
   */
  pr_list = HTRequest_error (pr_request);
  if (pr_list != NULL) {
         HTError *pr_error;
         pr_error = (HTError *) HTList_firstObject (pr_list);
         err_code = HTErrors[HTError_index (pr_error)].code;
         fprintf (stdout, "GOT AN ERROR (%d-%s)\n", err_code,
HTErrors[HTError_index (pr_error)].msg);
  }
  /* Deallocate allocated resources. */
  HTRequest_delete (pr_request);
  HTFormat_deleteAll ();
  HT_FREE (pc_cwd);
  HT_FREE (pc_absolute_url);
  /* Terminate Libwww and exit */
  HTProfile_delete ();
  return err_code;
}
--
  ch.   |            Christian Ruetgers               |
        | 1komma6- Multimediale Dienstleistungen GmbH |
        |  Fon: (0251) 57297  Fax: 57296 Priv: 236076 |
        |      visit "http://www.1komma6.com"!        |
Received on Sunday, 5 September 1999 11:02:13 UTC