title: Boost Asio C++ HTTPS Request not hitting server. No errors
body: <p>I am trying to hit an endpoint using Boost asio ssl C++. Everything goes fine without any errors. But the request just doesnt hit the server. Following is the code:</p>
  
  <pre><code>    string protocol,domain,port,path;
      boost::regex ex("(http|https)://([^/ :]+):?([^/ ]*)(/?[^ #?]*)\\x3f?([^ #]*)#?([^ ]*)");
      boost::cmatch what;
      if(regex_match(url.c_str(), what, ex)) 
      {
      protocol= string(what[1].first, what[1].second);
      domain= string(what[2].first, what[2].second);
      port= string(what[3].first, what[3].second);
      path= string(what[4].first, what[4].second);
      }
      // Get a list of endpoints corresponding to the server name.
      boost::asio::io_service io_service;
      boost::asio::ssl::context ctx(ssl::context::sslv23);
      ctx.set_default_verify_paths();
      ctx.set_options(boost::asio::ssl::context::default_workarounds |
      boost::asio::ssl::context::verify_none );
      ssl_socket socket(io_service, ctx);
      tcp::resolver resolver(io_service);
      tcp::resolver::query query(domain.c_str(), port.c_str());
      tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
  
      socket.set_verify_mode(boost::asio::ssl::context::verify_none);
      // Try each endpoint until we successfully establish a connection.
  
      socket.set_verify_callback(verify_certificate);
      boost::asio::connect(socket.lowest_layer(), endpoint_iterator);
      socket.handshake(ssl_socket::client);
      socket.lowest_layer().set_option(tcp::no_delay(true));
      // Form the request. We specify the "Connection: close" header so that the
      // server will close the socket after transmitting the response. This will
      // allow us to treat all data up until the EOF as the content.
      boost::asio::streambuf request;
      std::ostream request_stream(&amp;request);
  
      request_stream &lt;&lt; "POST "&lt;&lt;path&lt;&lt;"/ssl HTTP/1.1 \r\n";
      request_stream &lt;&lt; "Host:" &lt;&lt; domain&lt;&lt;":"&lt;&lt;port &lt;&lt; "\r\n";
      request_stream &lt;&lt; "User-Agent: C/1.0";
      request_stream &lt;&lt; "Content-Type: application/vnd.api+json; charset=utf-8 \r\n";
      request_stream &lt;&lt; "Accept: */*\r\n";
      request_stream &lt;&lt; "Content-Length: " &lt;&lt; json.length() &lt;&lt; "\r\n"; 
      request_stream &lt;&lt; "Connection: close\r\n\r\n";  //NOTE THE Double line feed
      request_stream &lt;&lt; json&lt;&lt;"\r\n";
  
      request_stream &lt;&lt; std::cin.rdbuf() &lt;&lt; std::flush;
      int a=boost::asio::write(socket, request);
  
  
       bool verify_certificate(bool preverified, boost::asio::ssl::verify_context&amp; ctx)
         {
          /* char subject_name[256];
           X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
           X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256);
           std::cout &lt;&lt; "Verifying:\n" &lt;&lt; subject_name &lt;&lt; std::endl;*/
  
           return true;
         }
  </code></pre>
  
  <p>I am using a self signed certificate and I strongly believe that is the problem. But then, I am not getting any handshake errors either. What am I doing wrong here?</p>
  
  <p>EDIT:
  I am getting the following output:</p>
  
  <pre><code>    Connected to: 
      Response: short read
  </code></pre>
  
  <p>Now I am not sure why the connected to part is empty. I debugged and cross checked the fact that host, port and path variables are not empty.</p>