Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTPS request with Boost.Asio and OpenSSL
    primarykey
    data
    text
    <p>I'm trying to read the ticker symbol at <a href="https://mtgox.com/api/0/data/ticker.php" rel="nofollow noreferrer">https://mtgox.com/api/0/data/ticker.php</a> from my C++ application. I use Boost.Asio and OpenSSL because the service requires HTTPS.</p> <p>Boost version: 1.47.0</p> <p>OpenSSL: 1.0.0d [8 Feb 2011] Win32</p> <p>For the application; I took the example from <a href="http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/ssl/client.cpp" rel="nofollow noreferrer">http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/ssl/client.cpp</a> to get started and modified it as follows:</p> <p>This is where I want to connect to:</p> <pre><code>boost::asio::ip::tcp::resolver::query query("mtgox.com", "443"); </code></pre> <p>I set verification to none because the handshake fails otherwise. I'm not sure if this is a problem with mtgox or that this implementation is really strict because when I print the certificate to the screen it looks legit (and chrome has no problem with it when visiting the ticker page).</p> <pre><code>socket_.set_verify_mode(boost::asio::ssl::context::verify_none); </code></pre> <p>This is the request I send:</p> <pre><code>std::stringstream request_; request_ &lt;&lt; "GET /api/0/data/ticker.php HTTP/1.1\r\n"; request_ &lt;&lt; "Host: mtgox.com\r\n"; request_ &lt;&lt; "Accept-Encoding: *\r\n"; request_ &lt;&lt; "\r\n"; boost::asio::async_write(socket_, boost::asio::buffer(request_.str()), boost::bind(&amp;client::handle_write, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); </code></pre> <p>(full code: <a href="http://pastebin.com/zRTTqZVe" rel="nofollow noreferrer">http://pastebin.com/zRTTqZVe</a>)</p> <p>I run into the following error:</p> <pre><code>Connection OK! Verifying: /C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority Sending request: GET /api/0/data/ticker.php HTTP 1.1 Host: mtgox.com Accept-Encoding: * Sending request OK! Read failed: An existing connection was forcibly closed by the remote host </code></pre> <p>Am I going in the right direction with this? The error message isn't really descriptive of the problem and I don't know which step I did wrong.</p> <p><strong>Update:</strong> I used cURL to see what went wrong:</p> <pre><code>curl --trace-ascii out.txt https://mtgox.com/api/0/data/ticker.php </code></pre> <p>(full output: <a href="http://pastebin.com/Rzp0RnAK" rel="nofollow noreferrer">http://pastebin.com/Rzp0RnAK</a>) It fails during verification. When I connect with the "unsafe" parameter</p> <pre><code>curl --trace-ascii out.txt -k https://mtgox.com/api/0/data/ticker.php </code></pre> <p>(full output: <a href="http://pastebin.com/JR43A7ux" rel="nofollow noreferrer">http://pastebin.com/JR43A7ux</a>)</p> <p>everything works fine. </p> <p><strong>Fix:</strong></p> <ol> <li>I fixed the typo in the HTTP headers </li> <li>I added a root certificate and turned SSL verification back on.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload