Arguments from user in case of Post Request

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Arguments from user in case of Post Request

neelu_dhiman
Hi folks,
I have written a Post Request code for Login, in which I have
to supply the user name and password as arguments with uri on
the command line. But I want to take user name and password
from the user. But the problem is, while parsing the
arguments, we have a function HTParseFormInput, which takes
arguments as 'argument=value' string, but I only want to pass
the value. Is there any other method that can be helpful ?
I am attaching the code for your reference.


// Post a Request //
#include <w3c-libwww/WWWLib.h>
#include <w3c-libwww/WWWInit.h>
PRIVATE HTChunk * result = NULL;
PRIVATE int printer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stdout, fmt, pArgs));
}
PRIVATE int tracer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stderr, fmt, pArgs));
}
PRIVATE int terminate_handler (HTRequest * request, HTResponse * response, void * param, int status)
{
    HTPrint("Status=%d\n",status);
    if (status == HT_LOADED || result || HTChunk_data(result))
    {
        char *data;
        FILE *fp;
        int i;
        data=HTChunk_data(result);
        fp=fopen("Login_Page.txt","w");
        for(i=0;data[i]!='\0';i++)
                fputc(data[i],fp);
     }
    HTChunk_delete(result);
    HTRequest_delete(request);
    HTProfile_delete();
    exit(0);
}
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTAnchor * anchor = NULL;
    HTAssocList * formfields = NULL;
    char * uri = NULL;
    HTProfile_newNoCacheClient("TestApp", "1.3");
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);
    /* Get trace messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
    HTHost_setEventTimeout(100000);
    if (argc >= 2)
    {
        int arg;
        uri = argv[1];
        for (arg=2; arg<argc; arg++)
       {
            char * string = argv[arg];
            if (!formfields) formfields = HTAssocList_new();
            HTParseFormInput(formfields, string);
        }
    }
    if (uri && formfields)
    {
        request = HTRequest_new();
        HTRequest_setOutputFormat(request, WWW_RAW);
        anchor = HTAnchor_findAddress(uri);
        result = HTPostFormAnchorToChunk(formfields, anchor, request);
        HTAssocList_delete(formfields);
        HTEventList_loop(request);
    } else {
        HTPrint("Type the URI to post to and the arguments for the POST operation. Encode spaces as '+'\n");
        HTPrint("\t%s <uri> 'a=1' 'b=+2+' 'c=3 ...'\n", argv[0]);
    }
    return 0;
}
Reply | Threaded
Open this post in threaded view
|

RE: Arguments from user in case of Post Request

Adam Mlodzinski

Each field in the form you are posting to has an associated "name"
attribute - this is how the web application distinguishes the purpose of
a value (basic HTML). So, if the users name goes into a field with the
name "field_two", the argument to HTParseFormInput would be
"field_two=argv[1]".

Examine your html form to find the name values you need to use.

--
Adam Mlodzinski



----Original Message----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of [hidden email]
Sent: Thursday, May 11, 2006 7:49 AM
To: [hidden email]
Subject: Arguments from user in case of Post Request

> Hi folks,
> I have written a Post Request code for Login, in which I have
> to supply the user name and password as arguments with uri on
> the command line. But I want to take user name and password
> from the user. But the problem is, while parsing the
> arguments, we have a function HTParseFormInput, which takes
> arguments as 'argument=value' string, but I only want to pass
> the value. Is there any other method that can be helpful ?
> I am attaching the code for your reference.