<bdo id='DeVkw'></bdo><ul id='DeVkw'></ul>

    <tfoot id='DeVkw'></tfoot>
  1. <small id='DeVkw'></small><noframes id='DeVkw'>

      <legend id='DeVkw'><style id='DeVkw'><dir id='DeVkw'><q id='DeVkw'></q></dir></style></legend>

      <i id='DeVkw'><tr id='DeVkw'><dt id='DeVkw'><q id='DeVkw'><span id='DeVkw'><b id='DeVkw'><form id='DeVkw'><ins id='DeVkw'></ins><ul id='DeVkw'></ul><sub id='DeVkw'></sub></form><legend id='DeVkw'></legend><bdo id='DeVkw'><pre id='DeVkw'><center id='DeVkw'></center></pre></bdo></b><th id='DeVkw'></th></span></q></dt></tr></i><div id='DeVkw'><tfoot id='DeVkw'></tfoot><dl id='DeVkw'><fieldset id='DeVkw'></fieldset></dl></div>
    1. 使用 Boost.Asio 和 OpenSSL 的 HTTPS 请求

      HTTPS request with Boost.Asio and OpenSSL(使用 Boost.Asio 和 OpenSSL 的 HTTPS 请求)
      <i id='U8Wsv'><tr id='U8Wsv'><dt id='U8Wsv'><q id='U8Wsv'><span id='U8Wsv'><b id='U8Wsv'><form id='U8Wsv'><ins id='U8Wsv'></ins><ul id='U8Wsv'></ul><sub id='U8Wsv'></sub></form><legend id='U8Wsv'></legend><bdo id='U8Wsv'><pre id='U8Wsv'><center id='U8Wsv'></center></pre></bdo></b><th id='U8Wsv'></th></span></q></dt></tr></i><div id='U8Wsv'><tfoot id='U8Wsv'></tfoot><dl id='U8Wsv'><fieldset id='U8Wsv'></fieldset></dl></div>
      <legend id='U8Wsv'><style id='U8Wsv'><dir id='U8Wsv'><q id='U8Wsv'></q></dir></style></legend>

            <tbody id='U8Wsv'></tbody>
            <bdo id='U8Wsv'></bdo><ul id='U8Wsv'></ul>
          • <small id='U8Wsv'></small><noframes id='U8Wsv'>

                <tfoot id='U8Wsv'></tfoot>
                本文介绍了使用 Boost.Asio 和 OpenSSL 的 HTTPS 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试阅读 https://mtgox.com 上的股票代码/api/0/data/ticker.php 来自我的 C++ 应用程序.我使用 Boost.Asio 和 OpenSSL,因为该服务需要 HTTPS.

                I'm trying to read the ticker symbol at https://mtgox.com/api/0/data/ticker.php from my C++ application. I use Boost.Asio and OpenSSL because the service requires HTTPS.

                增强版:1.47.0

                OpenSSL:1.0.0d [2011 年 2 月 8 日] Win32

                OpenSSL: 1.0.0d [8 Feb 2011] Win32

                对于应用程序;我从 http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/ssl/client.cpp开始并修改如下:

                For the application; I took the example from http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/ssl/client.cpp to get started and modified it as follows:

                这是我想要连接的地方:

                This is where I want to connect to:

                boost::asio::ip::tcp::resolver::query query("mtgox.com", "443");
                

                我将验证设置为无,因为否则握手会失败.我不确定这是 mtgox 的问题还是这个实现真的很严格,因为当我将证书打印到屏幕上时它看起来是合法的(并且在访问股票代码页面时 chrome 没有问题).

                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).

                socket_.set_verify_mode(boost::asio::ssl::context::verify_none);
                

                这是我发送的请求:

                std::stringstream request_;
                
                request_ << "GET /api/0/data/ticker.php HTTP/1.1
                ";
                request_ << "Host: mtgox.com
                ";
                request_ << "Accept-Encoding: *
                ";
                request_ << "
                ";
                
                boost::asio::async_write(socket_, boost::asio::buffer(request_.str()), boost::bind(&client::handle_write, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
                

                (完整代码:http://pastebin.com/zRTTqZVe)

                我遇到了以下错误:

                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
                

                我是否朝着正确的方向前进?错误消息并没有真正描述问题,我不知道我做错了哪一步.

                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.

                更新:我使用 cURL 查看出了什么问题:

                Update: I used cURL to see what went wrong:

                curl --trace-ascii out.txt https://mtgox.com/api/0/data/ticker.php
                

                (完整输出:http://pastebin.com/Rzp0RnAK)在验证过程中失败.当我连接不安全"参数时

                (full output: http://pastebin.com/Rzp0RnAK) It fails during verification. When I connect with the "unsafe" parameter

                curl --trace-ascii out.txt -k https://mtgox.com/api/0/data/ticker.php
                

                (完整输出:http://pastebin.com/JR43A7ux)

                一切正常.

                修正:

                1. 我修正了 HTTP 标头中的拼写错误
                2. 我添加了一个根证书并且重新开启 SSL 验证.

                推荐答案

                简而言之:

                1. 您发送的是HTTP 1.1"而不是HTTP/1.1".这肯定足以让服务器拒绝您的请求.您的请求和 cURL 之间还有其他差异,您可能还需要更改这些参数 - 即使它们对我来说似乎有效.

                1. You send "HTTP 1.1" instead of "HTTP/1.1". That's surely enough to make the server refuse your request. There are other differences between your request and cURL's, you might need to change those params as well - even if they seem valid to me.

                也许 OpenSSL 没有服务器使用的根证书,这与 Chrome 不同,这就是验证失败的原因.

                Maybe OpenSSL does not have the root certificate used by the server, unlike Chrome, and that's why verification is failing.

                详情:

                1. 给定一个工作和非工作工具,你应该总是比较正在发生的事情.在这里,您有 cURL 的输出和您的请求 - 比较它们显示了许多差异;通常,即使使用加密连接,您也可以使用强大的数据包嗅探器,例如 Wireshark,它会从数据包中解码尽可能多的信息.在这里它可以看到服务器实际上发送的数据包更少(我期望);另一种可能性是您的客户端没有收到服务器发送的数据(比如因为客户端有一些错误).

                1. Given a working and non-working tool, you should always compare what's happening. Here you have cURL's output and your request - comparing them showed a number of differences; usually, even with an encrypted connection, you can use a powerful packet sniffer like Wireshark, which decodes as much information from the packets as possible. Here it would allow to see that the server is actually sending less packets (I expect); another possibility would have been that your client was not getting the data sent by the server (say because the client had some bug).

                如果我理解正确,curl 只显示了您需要禁用验证的原因,对吗?该证书在 chrome 上对我来说也是有效的,但根证书颁发机构是未知的;curl 提到了CA cert",即证书颁发机构的证书.根证书是可信的,因为它已经存在于客户端的证书数据库中 - 我认为 Chrome 可能拥有比 OpenSSL 更完整的数据库(cURL 和您的程序都使用它).

                If I understand correctly, curl showed only why you needed to disable verification, right? The certificate looks valid for me on chrome as well, but the root certification authority is quite unknown; curl mentions the "CA cert", i.e. the certificate of the certification authority. The root certificate is trusted because it is already present in a certificate DB on the client - I think that Chrome might have a more complete DB than OpenSSL (which is used by both cURL and your program).

                这篇关于使用 Boost.Asio 和 OpenSSL 的 HTTPS 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                How boost auto-linking makes choice?(boost自动链接如何做出选择?)
                  <tbody id='hBNNw'></tbody>

                    <i id='hBNNw'><tr id='hBNNw'><dt id='hBNNw'><q id='hBNNw'><span id='hBNNw'><b id='hBNNw'><form id='hBNNw'><ins id='hBNNw'></ins><ul id='hBNNw'></ul><sub id='hBNNw'></sub></form><legend id='hBNNw'></legend><bdo id='hBNNw'><pre id='hBNNw'><center id='hBNNw'></center></pre></bdo></b><th id='hBNNw'></th></span></q></dt></tr></i><div id='hBNNw'><tfoot id='hBNNw'></tfoot><dl id='hBNNw'><fieldset id='hBNNw'></fieldset></dl></div>

                    <small id='hBNNw'></small><noframes id='hBNNw'>

                          <bdo id='hBNNw'></bdo><ul id='hBNNw'></ul>
                        • <tfoot id='hBNNw'></tfoot>
                        • <legend id='hBNNw'><style id='hBNNw'><dir id='hBNNw'><q id='hBNNw'></q></dir></style></legend>