How to POST?

Hello,

I tried to write a simple program that works like chunkbody.c but with
POST method. Though I read the Library documents, and www-lib mailing
list archive, still I don't know what to do with the message I got
below, when running the program.

...
Host Event.. FLUSH passed to `http://www.shiratori.riec.tohoku.ac.jp/~chotipat/cgi-bin/post-query.cgi'
Buffer...... Flushing 631e8
Write Socket 314 bytes written to 4
MIME........ Sleeping for 2 secs
Event....... No handler registered
Event....... No handler registered
Posting Data Target WOULD BLOCK
chunk size = 0
Output string is (null)
Request..... Delete 569c0
WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE
Net Object.. Kill ALL Net objects!!!
Net Object.. Killing 58448
Error....... Add  58    Severity: 1     Parameter: `Unspecified'        Where: `HTLoadHTTP'
HTTP Clean.. Called with status -902, net 58448
HTTPGen..... ABORTING...
HTTPRequest. ABORTING...
Buffer...... ABORTING...
FileWriter.. ABORTING...
MIMERequest. ABORTING...
...

If you know how to fix this problem, please let me know. I also attach my
program with this email.

Thanks in advance,

Chotipat

----------------------------------------------------------------------------

/* chunkbody with POST method */

#include "WWWLib.h"
#include "WWWHTTP.h"
#include "WWWInit.h"
#include "HTAccess.h"

#define POST_FORM_URL      "http://www.shiratori.riec.tohoku.ac.jp/~chotipat/cgi-bin/post-query.cgi"

/* main */
void main(void)
{
    char *keywords, *category;

    HTList *converters = HTList_new();		
    HTList *encodings = HTList_new();		
    HTRequest *request = HTRequest_new();

    char *escaped_keywords, *escaped_category;
    char *result = NULL;
    HTAssocList *formfields = NULL;
    HTChunk *chunk = NULL;
    HTStream *outstream = NULL;
    HTAnchor *anchor = HTAnchor_findAddress(POST_FORM_URL);

    puts("HTTP/1.0 200 OK");
    printf("Content-Type: text/html\r\n\r\n");
    HTLibInit("test_post", "0.1");

#if 1
    WWWTRACE = SHOW_CORE_TRACE + SHOW_STREAM_TRACE + SHOW_PROTOCOL_TRACE;
#endif

    HTTransportInit();
    HTProtocolInit();
    HTNetInit();
    HTConverterInit(converters);
    HTFormat_setConversion(converters);
    HTTransferEncoderInit(encodings);
    HTFormat_setTransferCoding(encodings);
    HTMIMEInit();
    HTRequest_setOutputFormat(request, WWW_SOURCE);
    HTRequest_setPreemptive(request, YES);
    HTRequest_setFlush(request, YES);

    keywords = "abc";
    category = "def";

    escaped_keywords = HTEscape(keywords, URL_XALPHAS);
    escaped_category = HTEscape(category, URL_XALPHAS);
    formfields = HTAssocList_new();
    HTAssocList_addObject(formfields, "input1", escaped_keywords);
    HTAssocList_addObject(formfields, "input2", escaped_category);

    outstream = HTStreamToChunk(request, &chunk, 0);
    HTRequest_setOutputStream(request, outstream);
    HTRequest_setAnchor(request, anchor);

    if(HTPostFormAnchor(formfields, anchor, request) != NULL)
        result = HTChunk_toCString(chunk);
    printf("chunk size = %d\n", HTChunkSize(chunk));
    HTChunk_delete(chunk);
    printf("Output string is %s\n", result);

    HTRequest_delete(request);
    HTFormat_deleteAll();
    HTLibTerminate();
}

Received on Wednesday, 28 January 1998 14:28:58 UTC