HTRequest -- making multiple requests

We are using the HTRequest family of functions to try and make multiple
calls to a server.We have it working fine just sending one call to the
server and closing the connection. But there are times we'd like to send
several chunks to the server and receive chunks back. This is what we
are doing that is working fine for a single call. We tried changing the
HTRequest_addConnection to change the second parameter to "Keep-Alive"
instead of "close" in the hopes that would keep it open. But we still
could only send one chunk to the server. How do we change this to allow
multiple calls to the server?



#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/uswitch.h>
#include <time.h>
#include <netinet/in.h>
#include <stdlib.h>
#include "xmlrpc.h"




HTChunk * chunk = NULL;

PRIVATE int printer (const char *fmt, va_list pArgs) {}
PRIVATE int tracer (const char *fmt, va_list pArgs) {}


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)
{
    HTEventList_stopLoop();
    return HT_OK;
}

void process_echeck (char *state,  char *inmerch, char *intrantyp, char
*inpymtopt, char *inbtn,
                      char *inacct,char *incsind, char *inamount, char
*inpersonid, char *inname,
                      char *inbrowserip, char *rtncode, char *rtnmessage,
char *rtnseqnum, char *rtnamount)
{
         int length, start, intVal;

         HTRequest * request = NULL;
         HTParentAnchor * src = NULL;
         HTAnchor * dst = NULL;

         char * dst_str = "http://itnt104.it.wsu.edu/xml-rpc/echeck.asp";
         char * returnBuf;
         char * OutBuf;
         char * returnBuf2;
         char * string;
         char * merch;

         HTPrint_setCallback(printer);
         HTTrace_setCallback(tracer);

     /* 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);
     /*      xmlbuf is our routine to put the parms into XML.
             not included here to save space */
         OutBuf = (char*) strdup(xmlbuf(inmerch, intrantyp, inpymtopt,
inbtn, inacct,
         incsind, inamount, inpersonid, inname, inbrowserip));
         request = HTRequest_new();
         HTRequest_setOutputFormat(request, WWW_RAW);
         HTRequest_addConnection(request,state,"");

         dst = HTAnchor_findAddress(dst_str);
         src = HTTmpAnchor(NULL);
         HTAnchor_setDocument(src, OutBuf);
         HTAnchor_setLength(src, strlen(OutBuf));

         chunk = PostAnchorToChunk(src, dst, request);

         if (chunk) {
                 HTEventList_loop(request);
                 returnBuf = strdup(HTChunk_toCString(chunk));
         }

         HTRequest_delete(request);
         HTFormat_deleteAll();
         HTLibTerminate();
         length = (int)strlen(returnBuf);
         start = string_index(returnBuf,"<?xml ");

         length = length - start;
         returnBuf = substr(returnBuf, start, length);


         return;
}


John Chapman
Information Technology          (509) 335-7350 (voice)
Washington State University     (509) 335-0540 (fax)
john_chapman@wsu.edu          (509) 336-4100 (pager)

Received on Thursday, 2 January 2003 17:55:21 UTC