bs1977's picture

Hi All, 
I need to post data to outside web server from my C++ application using HTTP POST and looking for best client side library. I'm thinking to use cURL but since my application already uses boost library so wondering if PION can do this job easily. I looked samples but manly they are focussed on server side. Can  anyone please point me right place to look into ?  I was looking  HTTPResuestWrite.cpp, HTTPResuest.hpp but any help would be highly appreciated.
Thanks

Mike Dickey's picture
Although it is not well

Although it is not well documented, you can use pion-net to send client-send HTTP requests, both synchronously and asynchronously. Here is a snippet that I haven't tested but should give you a good idea how this works:

boost::system::error_code error_code;

// connect to remote server
TCPConnection tcp_conn;
error_code = tcp_conn.connect("myserver", 80);
if (error_code) throw error_code; // connection failed

// send HTTP request
HTTPRequest http_request("/index.html");
http_request.setMethod("POST");
http_request.addHeader("Content-Type", MY_POST_CONTENT_TYPE);
http_request.setContent(MY_POST_CONTENT);
http_request.send(tcp_conn, error_code);
if (error_code) throw error_code; // connection failed

// receive HTTP response
HTTPResponse http_response(http_request);
http_response.receive(tcp_conn, error_code);
if (error_code) throw error_code; // connection failed

Submitted by Mike Dickey on Mon, 04/05/2010 - 09:09.