- From: <mnautiyal@hss.hns.com>
- Date: Wed, 19 Dec 2001 20:43:43 +0530
- To: Nandika Mirihana <Nandika@eRunway.com>
- cc: www-lib@w3.org
Hi, Hope you got some solution by now. I had similar requirement like as follows : 1) post XML encoded buffer to a particular servlet (URL) and wait for response 2) The response data should be read by the application and process it. For that, I disbled the prompt (HT_A_PROMPT) by library and instead attached a simple callback for the same prompt. Following is the sample : /* Initiate libwww :- Create a new premptive client */ HTProfile_newNoCacheClient(appName, "1.0"); /* Add our own filter to update the history list */ HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST); /* find the Alert callback "HTPrompt" */ cbf = HTAlert_find (HT_A_PROMPT); if (HTAlert_delete (cbf) == NO) { printf "Failed to delete default library callback <HTPrompt>\n"); return; } /* add our own callback, It will be called by the libwww library */ HTAlert_add(saveResponseInFile, HT_A_PROMPT); if (data && *data && dst_str && *dst_str) { /* Make source relative to where we are */ char * cwd = HTGetCurrentDirectoryURL(); printf("Posting to %s\n",dst_str); /* Create a request */ request = HTRequest_new(); /* Get an anchor object for the destination URI */ dst = HTAnchor_findAddress(dst_str); /* ** Dream up a source anchor (an editor can for example use this). ** After creation we associate the data that we want to post and ** set some metadata about what the data is. More formats can be found ** ../src/HTFormat.html */ src = HTTmpAnchor(NULL); HTAnchor_setDocument(src, data); HTAnchor_setFormat(src, WWW_PLAINTEXT); /* ** If not posting to an HTTP/1.1 server then content length MUST be ** there. If HTTP/1.1 then it doesn't matter as we just use chunked ** encoding under the covers */ HTAnchor_setLength(src, strlen(data)); /* POST the source to the dest */ status = HTPostAnchor(src, dst, request); printf ("Posted data to URL.\nWaiting for response...."); /* We don't need these anymore */ HT_FREE(cwd); /* Go into the event loop... */ if (status == YES) HTEventList_loop(request); } } However, I have still more to find and would appreciate any sort of help : 1) How should I do it without having the response data to be saved in a file Instead simply get it in buffer , and 2) For a request, its blocked until it gets response, if I'm correct. So how should have multiple non blocking requests. I would work to find these, but would appreciated any help/suggestion for the same. Regards, Manoj Nandika Mirihana <Nandika@eRunway.com> on 12/18/2001 08:43:14 AM To: www-lib@w3.org cc: (bcc: Manoj Nautiyal/HSS) Subject: pls help me to send a request with data and get a response. Hi , I am a new commer to the libwww. I want to post data to remote server and get response. I have already send a request ( without data) to the remote http server . but it is not the response that I want . This is my code int HTTPPost::sendRequest() { HTRequest * request = NULL; HTParentAnchor * src = NULL; HTAnchor * dst = NULL; HTChunk * chunck = NULL; char * dst_str = NULL; char * data = NULL; BOOL status = NO; HTChunk* p_pphc_responseData = NULL; dst_str ="http://nagoya.apache.org:5049"; //:5049/axis/servlet/AxisServlet"; data = "hello"; if (data && *data && dst_str && *dst_str) { /* Make source relative to where we are */ char * cwd = HTGetCurrentDirectoryURL(); HTPrint("Posting to %s\n", dst_str); /* Create a request */ request = HTRequest_new(); //set the output format and target stream HTRequest_setOutputStream(request, HTStreamToChunk(request, &p_pphc_responseData, -1)); HTRequest_setOutputFormat(request, HTAtom_for("text/xml")); /* Get an anchor object for the destination URI */ dst = HTAnchor_findAddress(dst_str); /* ** Dream up a source anchor (an editor can for example use this). ** After creation we associate the data that we want to post and ** set some metadata about what the data is. More formats can be found ** ../src/HTFormat.html */ src = HTTmpAnchor(NULL); HTAnchor_setDocument(src, data); HTAnchor_setFormat(src, WWW_PLAINTEXT); /* ** If not posting to an HTTP/1.1 server then content length MUST be ** there. If HTTP/1.1 then it doesn't matter as we just use chunked ** encoding under the covers */ HTAnchor_setLength(src, strlen(data)); /* POST the source to the dest */ status = HTPostAnchor(src, dst, request); //status = HTTraceAbsolute (dst_str,request); /* We don't need these anymore */ HT_FREE(cwd); /* Go into the event loop... */ if (status == YES) HTEventList_loop(request); } return 0; } This is the output Posting to http://nagoya.apache.org:5049 Looking up nagoya.apache.org Looking up nagoya.apache.org Contacting nagoya.apache.org Writing 1Kbytes Reading... Reading... Read 1Kbytes Done! A redirection may change the behavior of this method - proceed anyway? (y/n) y Writing 1Kbytes Reading... Reading... Please give name of file to save in: (RETURN for [C:\Temp\index.html]) Read (0% of 7K) Done! I don't know how "A redirection may change the behavior of this method - proceed anyway? (y/n) y" and "Please give name of file to save in: (RETURN for [C:\Temp\index.html])" come pls help me to send a request with data and get a response. Thank you Regards, -Nandika
Received on Wednesday, 19 December 2001 10:20:14 UTC