Basically a have the code to make an http call to server and handle the response but I want to secure the data travelling and make the call https.
For that I have this executor.hpp
class Executor
{
public :
Executor(Cli &cli):ssock(svc)
{
//! Get a list of endpoints corresponding to the server name.
boost::asio::ip::tcp::resolver resolver(svc);
boost::asio::ip::tcp::resolver::query query(cli.getIP(), "8080");
endpoint_iterator = resolver.resolve(query);
}
int connect();
int write(RequestCreator &requestcreator);
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &getSocket() { return ssock; }
private :
boost::asio::io_service svc;
boost::asio::ssl::context ctx(svc, ssl::context::method::sslv23_client);
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssock(svc, ctx);
boost::asio::ip::tcp::resolver::iterator endpoint_iterator;
};
and this executor.cpp
int Executor::connect()
{
boost::system::error_code ec ;
boost::asio::connect(ssock.lowest_layer(), endpoint_iterator );
ssock.handshake(boost::asio::ssl::stream_base::handshake_type::client);
if (ec)
{
ssock.lowest_layer().close();
svc.stop();
return 0;
}
return 1;
}
int Executor::write(RequestCreator &requestCreator)
{
boost::system::error_code ec ;
boost::asio::write(ssock, requestCreator.getRequest(), ec);
if (ec)
{
ssock.lowest_layer().close();
svc.stop();
return 0;
}
return 1;
}
and below is the full error on compiler
c:\cygwin64\home\admin\sandbox\webcli\executor.hpp(30) : error C2061: syntax error : identifier 'svc'
c:\cygwin64\home\admin\sandbox\webcli\executor.hpp(31) : error C2061: syntax error : identifier 'svc'
c:\cygwin64\home\admin\sandbox\webcli\executor.hpp(15) : error C2436: 'ssock' : member function or nested class in constructor initializer list
c:\cygwin64\home\admin\sandbox\webcli\executor.hpp(25) : error C3867: 'Executor::ssock': function call missing argument list; use '&Executor::ssock' to create a pointer to member
c:\cygwin64\home\admin\sandbox\webcli\executor.hpp(25) : error C2440: 'return' : cannot convert from 'boost::asio::ssl::stream<Stream> (__cdecl Executor::* )(void)' to 'boost::asio::ssl::stream<Stream> &'
with
[
Stream=boost::asio::ip::tcp::socket
]
The error message refers to a class
Executor
which isn't in your code. Are you compiling the right thing?boost::asio::ssl::context ctx(svc, ssl::context::method::sslv23_client);
this should not compile, unless
svc
is also a type in your code. Use braces.boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssock(svc, ctx);
This will most definitely not compile then. Same problem.
Connect(Data &data) : socket(ioService) {
ssock
).ioService
is not declared. What is it? (Assuming you might have meantsvc
).Contrast
with
Which is it? Compilers are not going to guess what you mean. If you mean
RequestCreator
you're gonna have to type that, and notCreatRequest
.All in all, there's no real question, just a lot of blindly copied/paste "code-like" text.
Fixing all the above in the most straightforward way possible:
Live On Coliru