catching something from the server output stream or something :(

Hello,
regarding my previous question, maybe the exact question is :
How can I 'catch' the stream sent from the server (that is, when I wrote some client that send a POST, for example).. 'Coz, printf from the chunk didn't result anything (maybe the server didn't send anything back at the chunk, but it indeed send something to my output stream - hence I can see the output in my screen). Of course, I can pipe it's output to a file..

thanks in advance,

---------- Original Message ----------------------------------
From: Stewart Johnson <stewart.johnson@ieee.org>
Date: Wed, 28 May 2003 02:55:04 +0930

>
>
>Phooey. I just noticed:
>
>http://www.w3.org/Library/src/HTProfil.html
>
>"Do not use preemptive profiles if you are doing PUT or POST requests."
>
>So I've switched back to HTProfile_newRobot().
>
>On Wednesday 28 May 2003 2:51 am, Stewart Johnson wrote:
>> Hi Nino --
>>
>> It just so happens I'm working on this right now. Here's what I'm working
>> with at the moment (cmments below):
>>
>> --------- begin code ----------
>> #include "WWWLib.h"
>> #include "WWWInit.h"
>> #include "WWWSSL.h"
>>
>> int main ()
>> {
>>     HTRequest * request = NULL;
>>     HTAnchor * anchor = NULL;
>>     HTAssocList * formfields = NULL;
>>     char uri[] = "https://accounts.internode.on.net/cgi-bin/padsl-usage";
>>     char arg1[] = "username=XXXX";
>>     char arg2[] = "password=YYYY";
>>     formfields = HTAssocList_new();
>>     HTParseFormInput(formfields, arg1);
>>     HTParseFormInput(formfields, arg2);
>>
>>     /* create a new pre-emptive client, doesn't use event loop */
>>     HTProfile_newPreemptiveClient("Sample Post Client", "0.1");
>>
>>     /* SSL initialisation */
>>     HTSSL_protMethod_set (HTSSL_V23);
>>     HTSSL_verifyDepth_set (2);
>>     HTSSLhttps_init(NO);
>>
>>     /* Create a request */
>>     request = HTRequest_new();
>>
>>     /* Get an anchor object for the URI */
>>     anchor = HTAnchor_findAddress(uri);
>>
>>     /* Post the data and get the result in a chunk */
>>     HTChunk * result = HTPostFormAnchorToChunk(formfields, anchor,
>> request);
>>
>>     printf("The result from the server was: \"%s\"\n",
>> HTChunk_data(result));
>>
>>     HTAssocList_delete(formfields);/* Clean up the form fields */
>>     HTRequest_delete(request);  /* Destroy the Request object */
>>     HTSSLhttps_terminate();     /* Unregister SSL app support */
>>     HTProfile_delete();         /* Terminate HTTP client      */
>>     return 0;
>> }
>>
>> --------- end code ----------
>>
>> This seems to be heading down the right track, I'm no longer using the
>> event loop. I got the idea of using HTProfile_newPreemptiveClient from:
>>
>> http://www.w3.org/Library/Examples/libapp_4.c
>>
>> The only problem now is that it's not waiting for the request to complete:
>> the request is deleted before it's finished being handled:
>> [stew@uno cpp]$ g++ -o runme simple.c `libwww-config --cflags`
>> `libwww-config --libs` -L/usr/lib -lwwwssl
>> [stew@uno]$ ./runme
>> Looking up accounts.internode.on.net
>> Looking up accounts.internode.on.net
>> Contacting accounts.internode.on.net
>> The result from the server was: "(null)"
>> Interrupted!
>>
>> Like I said, I'm still working on it! Any ideas appreciated!
>>
>> Stewart.
>>
>> On Wednesday 28 May 2003 2:28 am, you wrote:
>> > Dear Stewart,
>> > I'm having the same problem too..
>> >
>> > ---------- Original Message ----------------------------------
>> > From: Stewart Johnson <stewart.johnson@ieee.org>
>> > Date: Mon, 26 May 2003 01:27:08 +0930
>> >
>> > >G'day --
>> > >
>> > >I've been using the the W3C libwww for a little while now, and I've
>> > > generally had success. I'm having trouble figuring a new problem out,
>> > > and I'm looking for some advice. Hopefully someone can find the time to
>> > > steer me in the right direction! :^)
>> > >
>> > >The tool I'm currently writing only ever needs to perform a POST request
>> > > on a single server. It does this request once every half an hour, so
>> > > for all intents and purposes the requests happen in isolation. I'm
>> > > writing this tool in C++.
>> > >
>> > >I have everything working okay, but I can't help but think there's an
>> > > easier (and less verbose) way to do it. I'm initialising the library,
>> > > creating my HTRequest and calling HTPostFormAnchorToChunk to get my
>> > > result. That all seems correct, my problem is the next part:
>> > >
>> > >I'm entering the eventloop using HTEventList_loop. I've previously
>> > > registered a terminate_handler callback to catch the HTResponse of my
>> > > HTRequest and save the status in the HTRequest's context, and then call
>> > > HTEventList_stopLoop. That seems like a whole bunch of unnecessary
>> > > effort. In addition, it feels ugly because the terminate_handler is a
>> > > static function.
>> > >
>> > >Is it easy to replace the HTEventList_loop? Is there another way of
>> > > firing off my single HTRequest and catching the response, preferably
>> > > all within the one function, rather than using a callback?
>> > >
>> > >Any advice is greatly appreciated.
>> > >
>> > >TIA,
>> > >Stewart.
>
>

Received on Thursday, 29 May 2003 10:26:34 UTC