|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Arguments from user in case of Post RequestHi 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; } |
|
|
|
| Free embeddable forum powered by Nabble | Forum Help |