Overview
Features
Download
Documentation
Community
Add-Ons & Services

how to set a form for post a request

Please post support and help requests here.

how to set a form for post a request

Postby gustavsen » 18 Nov 2008, 14:50

Hi, I look into all samples but don't saw hot to do it...
and I finally read the docs and try without success.
I must generate a XML and post to a URL for processing.
I write the next code but I don't send nothing when post it.

TIA
Gustavsen
PS: I disasembly the xml for avoid problem with forum

Code: Select all

#include "stdafx.h"
#include "HttpCliente.h"

#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/StreamCopier.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include
#include
#include

using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPMessage;
using Poco::Net::HTMLForm;
using Poco::StreamCopier;
using Poco::URI;
using Poco::Exception;

using namespace std;



int main(int argc, char* argv)
{
   cout << "begin" << endl;
   string xml = "< ?xml version="1.0"? >< request >THE XML< /request >

";

   URI uri("http://localhost:9980/");
   string path = uri.getPathAndQuery();
   HTTPClientSession session (uri.getHost(), uri.getPort());
   HTTPRequest request(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
   request.setContentType("text/xml; charset="iso-8859-1"");
   request.setKeepAlive(true);

      
   HTMLForm form (request);
   form.set("xml", xml);
   session.sendRequest(request);
   form.prepareSubmit(request);

   ostringstream oss;
   form.write(oss);

   string texto  = oss.str();
   cout << "form: " << texto << endl;
   istringstream iss(texto);

   cout << "request: " << endl;
   request.write(cout);
   cout << "fin request: " << endl;

   HTTPResponse response;

   istream& rs = session.receiveResponse(response);
   cout << response.getStatus() << " " << response.getReason() << endl;
   StreamCopier::copyStream(rs, cout);
   return 0;
}

 
gustavsen
 
Posts: 8
Joined: 21 Oct 2008, 14:24

Re: how to set a form for post a request

Postby gustavsen » 20 Nov 2008, 19:37

nobody can't help me?

I need use POCO for receive and response...

best regards
Gustavsen
gustavsen
 
Posts: 8
Joined: 21 Oct 2008, 14:24


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests