Overview
Features
Download
Documentation
Community
Add-Ons & Services

HTTP POST

Please post support and help requests here.

HTTP POST

Postby chriso » 29 Sep 2008, 16:49

Hi

I am new to Poco.

I'd like to send variables from my c++ application via http post to a php script online. Here is my code, based on some examples I've found:

Code: Select all

URI uri("http://www.chrisoshea.org/storage/temp/poco/post2me.php");
std:string path(uri.getPathAndQuery());
if (path.empty()) path = "/";

HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest:HTTP_POST, path, HTTPMessage:HTTP_1_1);

// create the form data to send
HTMLForm form(HTMLFormENCODING_MULTIPART);

// form values
const std:string name = "one";
const std:string val = "valuene";
form.set(name, val);

form.prepareSubmit(req);

form.write(session.sendRequest(req));
HTTPResponse res;
std:istream& rs = session.receiveResponse(res);
printf("---
");
std:cout << res.getStatus() << " " << res.getReason() << std:endl;
printf("---
");
StreamCopier:copyStream(rs, std:cout);


The return stream prints 'done' which is just inside my php, but doesn't show any of the variables posted.

The php just looks like this (and works from a normal html form)

foreach ($_REQUEST as $param => $value){
echo($param);
echo($value);
}

Any thoughts?

Many thanks
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: HTTP POST

Postby chriso » 29 Sep 2008, 16:52

sorry, the forum formatting on the code is weird, here is the code

http://www.chrisoshea.org/storage/temp/poco/source.txt
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: HTTP POST

Postby guenter » 30 Sep 2008, 18:04

It seems your PHP script or PHP in general does not understand Multipart encoded form data. I have changed the encoding passed to HTMLForm to from ENCODING_MULTIPART to ENCODING_URL, and the PHP returns the expected result.
guenter
 
Posts: 1165
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTP POST

Postby chriso » 03 Oct 2008, 12:35

thanks, this solved it.
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests