I am trying to write the synchronous SSL client here my code is:
class CHttps session {public: CHttps session (io_service & amp; io_service, SSL :: Reference and Reference, TCP :: Resolver :: Iterator EndpointErrorator): m_socket (io_service, context) {Error_code error = error :: host_not_found; TCP :: Resolter :: Iterator End; While (error & amp; endpointeritter! = End) {m_socket.lowest_layer (). Close (); M_socket.lowest_layer (). Connect (* endpointitter ++, error); } If (error) {system_error (error); } M_socket.handshake (SSL :: Stream_base :: Client); } Zero send request (CHTPRQUEST and request) {Write (M_Sock, request.Gaterequest ()); } Nil receive response (CHTTPPS and response) {streambuf; Errorgood error; Read (m_socket, reply, transfer_all (), error); // here is the error (error & error! = Error :: uof) system_error (error); Response.init (answers); } Private: SSL :: Stream & lt; Tcp :: socket & gt; M_socket; } Int main (int argc, char * argv []) {try {io_service io_service; String server = "some servers here"; String port = "some ports here"; Tcp :: relay resolver (io_service); Tcp :: Resolver :: query query (std :: string (server), std :: to_string (port)); Tcp :: Resolver :: Iterator Endpoint_itator = Resolver Risol (query); Ssl :: Reference ctx (io_service, ssl :: context_base :: sslv23_client); Ctx.use_certificate_chain_file ("Path to certificate file"); Ctx.set_verify_mode (SSL :: context_base :: verify_none); Auto session = new CHttps session (io_service, ctx, endpointItterator); CHttpRequest request; CHttpResonse Reaction; // Request initialization session.sendRequest (request); Session.receiveResponse (feedback); } Catch (boost: system :: system_error & act) {cout & lt; & Lt; Exc.what () & lt; & Lt; Std :: endl; }}
But I get an error while trying to read the data by mistake: the request to send or receive data was rejected because the socket was closed in the direction with the previous shutdown
The built-in TCP socket is still open, the data is available through it, but since it is encrypted, I do not use it Can not.
No comments:
Post a Comment