Overview
Features
Download
Documentation
Community
Add-Ons & Services

HTTPClient and form submission

A general discussion forum.

HTTPClient and form submission

Postby euphreme » 23 Dec 2008, 18:31

Following the comments of a previous post: http://pocoproject.org/poco/wiki/tiki-v ... &forumId=1

Here's my code.
Code: Select all
   Poco::Net::HTTPResponse res;

   // On construit la requête.
   Poco::URI uri("http://10.1.2.145/form_0_io.htm");
   std::string path(uri.getPathAndQuery());
   
   Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
   Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPMessage::HTTP_1_1);   
      
   // On rempli les paramètres qu'on a besoin.
   Poco::Net::HTMLForm form(Poco::Net::HTMLForm::ENCODING_MULTIPART);
   
   form.set("InOu_2", "2");
   form.prepareSubmit(req);   
   form.write(session.sendRequest(req));

   session.receiveResponse(res);
   std::cout << res.getStatus() << " " << res.getReason() << std::endl;


It seems that the web server is getting the request, since I'm getting a 302 response, but looks like that the form parameters aren't considered, those parameters should trigger an automate and light up a bulb, but is not ...

But through the browser, it works well and gets also to the redirected page.
Html Code here:
Code: Select all
<html>
   <head><title>Test Form Submission</title></head>
   <body>
   
   <form action="http://10.1.2.145/form_0_io.htm" method="post">
      <input type="hidden" name="InOu_0" value="2"/>
      <input type="submit" value="Submit"/>
   </form>
   
   </body>
</html>


Any suggestions ?

Thank you
- Pascal
euphreme
 
Posts: 7
Joined: 26 Nov 2008, 21:53

Re: HTTPClient and form submission

Postby euphreme » 23 Dec 2008, 20:33

I finally found the problem.

I changed the code from

Code: Select all
Poco::Net::HTMLForm form(Poco::Net::HTMLForm::ENCODING_MULTIPART);

to
Code: Select all
Poco::Net::HTMLForm form(Poco::Net::HTMLForm::ENCODING_URL);


Thanks.
euphreme
 
Posts: 7
Joined: 26 Nov 2008, 21:53


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest