
I posted this as a reply below, but perhaps it's better as its own topic.
I'm trying to use the Pion net library (v2.0.10) to create an SSL client to connect to our Pion HTTP service. I'm having trouble with authentication. I've pieced together a code snippet below. The connection works but I get an authentication error. I can connect with Firefox so I know the HTTP service is operating properly and the username and password I'm using are the same. Can someone point out what I'm doing wrong? Thanks!
boost::shared_ptr context(
new pion::net::TCPConnection::SSLContext(scheduler.getIOService(),
boost::asio::ssl::context::sslv23));
TCPConnectionPtr tcp_conn(
new TCPConnection(scheduler.getIOService(), *context);
boost::system::error_code error_code;
error_code = tcp_conn->connect(endpoint->get_host(), endpoint->get_port());
if (error_code || !tcp_conn->is_open())
{
std::cout << "Socket connect FAILED: " << error_code << std::endl;
}
else
{
std::cout << "Socket connect succeeded: " << error_code << std::endl;
error_code = tcp_conn->handshake_client();
if (error_code)
{
std::cout << "Handshake FAILED!" << std::endl;
}
}
HTTPRequest request(endpoint->get_url());
PionUserPtr user(new PionUser(username, password));
request.setUser(user);
request.setContentType(HTTPTypes::CONTENT_TYPE_TEXT);
request.setMethod("POST");
request.setVersionMajor(1);
request.setVersionMinor(1);
request.addHeader("Host", endpoint->get_host());
request.setContentLength(input_data_size);
char* content = request.createContentBuffer();
memcpy((void*)content, (void*)input_data.get(), input_data_size);
boost::system::error_code error_code;
request.send(*tcp_conn, error_code);
if (!error_code)
{
HTTPResponse response(request);
response.receive(*tcp_conn, error_code);
....

The PionUser in HTTPRequest is currently only used when building requests server-side. The client library does not use it. Instead you will need to build the "Authorization" header for the HTTP request manually. Something like this:
string encoded;
string credentials(username + ":" + password);
HTTPTypes::base64_encode(credentials, encoded);
request.addHeader(HTTPTypes::HEADER_AUTHORIZATION, "Basic " + encoded);
- Login or register to post comments
Submitted by Mike Dickey on Thu, 09/03/2009 - 08:28.