久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <legend id='818SI'><style id='818SI'><dir id='818SI'><q id='818SI'></q></dir></style></legend>
      <tfoot id='818SI'></tfoot>
    1. <i id='818SI'><tr id='818SI'><dt id='818SI'><q id='818SI'><span id='818SI'><b id='818SI'><form id='818SI'><ins id='818SI'></ins><ul id='818SI'></ul><sub id='818SI'></sub></form><legend id='818SI'></legend><bdo id='818SI'><pre id='818SI'><center id='818SI'></center></pre></bdo></b><th id='818SI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='818SI'><tfoot id='818SI'></tfoot><dl id='818SI'><fieldset id='818SI'></fieldset></dl></div>
      • <bdo id='818SI'></bdo><ul id='818SI'></ul>

    2. <small id='818SI'></small><noframes id='818SI'>

      1. 將 cURL 內容結果保存到 C++ 中的字符串中

        Save cURL content result into a string in C++(將 cURL 內容結果保存到 C++ 中的字符串中)

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

          <tbody id='sL95L'></tbody>

        • <legend id='sL95L'><style id='sL95L'><dir id='sL95L'><q id='sL95L'></q></dir></style></legend>

                <i id='sL95L'><tr id='sL95L'><dt id='sL95L'><q id='sL95L'><span id='sL95L'><b id='sL95L'><form id='sL95L'><ins id='sL95L'></ins><ul id='sL95L'></ul><sub id='sL95L'></sub></form><legend id='sL95L'></legend><bdo id='sL95L'><pre id='sL95L'><center id='sL95L'></center></pre></bdo></b><th id='sL95L'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sL95L'><tfoot id='sL95L'></tfoot><dl id='sL95L'><fieldset id='sL95L'></fieldset></dl></div>
                • <bdo id='sL95L'></bdo><ul id='sL95L'></ul>
                  <tfoot id='sL95L'></tfoot>
                  本文介紹了將 cURL 內容結果保存到 C++ 中的字符串中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  int main(void)
                  {
                    CURL *curl;
                    CURLcode res;
                  
                    curl = curl_easy_init();
                    if(curl) {
                      curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
                      curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
                      curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
                      res = curl_easy_perform(curl);
                      curl_easy_cleanup(curl);
                    }
                    _getch();
                    return 0;
                  }
                  
                  string contents = "";
                  

                  我想將 curl html 內容的結果保存在一個字符串中,我該怎么做?這是一個愚蠢的問題,但不幸的是,我在 C++ 的 cURL 示例中找不到任何地方謝謝!

                  I would like to save the result of the curl html content in a string, how do I do this? It's a silly question but unfortunately, I couldn't find anywhere in the cURL examples for C++ thanks!

                  推薦答案

                  你將不得不使用 CURLOPT_WRITEFUNCTION 設置寫入回調.我現在無法測試編譯這個,但函數應該看起來很接近;

                  You will have to use CURLOPT_WRITEFUNCTION to set a callback for writing. I can't test to compile this right now, but the function should look something close to;

                  static std::string readBuffer;
                  
                  static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
                  { 
                      size_t realsize = size * nmemb;
                      readBuffer.append(contents, realsize);
                      return realsize;
                  }
                  

                  然后通過doing調用它;

                  Then call it by doing;

                  readBuffer.clear();
                  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
                  // ...other curl options
                  res = curl_easy_perform(curl);
                  

                  調用后,readBuffer應該有你的內容.

                  After the call, readBuffershould have your contents.

                  您可以使用 CURLOPT_WRITEDATA 來傳遞緩沖區字符串,而不是將其設為靜態.在這種情況下,為了簡單起見,我只是將其設為靜態.一個很好看的頁面(除了上面鏈接的例子)是這里的解釋的選項.

                  You can use CURLOPT_WRITEDATA to pass the buffer string instead of making it static. In this case I just made it static for simplicity. A good page to look (besides the linked example above) is here for an explanation of the options.

                  Edit2:根據要求,這是一個沒有靜態字符串緩沖區的完整工作示例;

                  As requested, here's a complete working example without the static string buffer;

                  #include <iostream>
                  #include <string>
                  #include <curl/curl.h>
                  
                  
                  static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
                  {
                      ((std::string*)userp)->append((char*)contents, size * nmemb);
                      return size * nmemb;
                  }
                  
                  int main(void)
                  {
                    CURL *curl;
                    CURLcode res;
                    std::string readBuffer;
                  
                    curl = curl_easy_init();
                    if(curl) {
                      curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
                      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
                      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
                      res = curl_easy_perform(curl);
                      curl_easy_cleanup(curl);
                  
                      std::cout << readBuffer << std::endl;
                    }
                    return 0;
                  }
                  

                  這篇關于將 cURL 內容結果保存到 C++ 中的字符串中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)

                  1. <tfoot id='qXStE'></tfoot>
                    <legend id='qXStE'><style id='qXStE'><dir id='qXStE'><q id='qXStE'></q></dir></style></legend>
                      <tbody id='qXStE'></tbody>
                  2. <small id='qXStE'></small><noframes id='qXStE'>

                          <bdo id='qXStE'></bdo><ul id='qXStE'></ul>
                          <i id='qXStE'><tr id='qXStE'><dt id='qXStE'><q id='qXStE'><span id='qXStE'><b id='qXStE'><form id='qXStE'><ins id='qXStE'></ins><ul id='qXStE'></ul><sub id='qXStE'></sub></form><legend id='qXStE'></legend><bdo id='qXStE'><pre id='qXStE'><center id='qXStE'></center></pre></bdo></b><th id='qXStE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qXStE'><tfoot id='qXStE'></tfoot><dl id='qXStE'><fieldset id='qXStE'></fieldset></dl></div>
                            主站蜘蛛池模板: 国产探花在线观看视频 | 精品国产三级 | 免费av在线 | 国产精品伦一区二区三级视频 | 草久久久 | 精品国产精品三级精品av网址 | 日日摸天天添天天添破 | 日本a在线 | 日韩精品免费在线观看 | 91国在线| 免费av手机在线观看 | 久久一二 | 一区二区三区视频免费观看 | 91在线看| 国产精品一级在线观看 | 欧美一级淫片免费视频黄 | 色综合一区二区三区 | 久久99蜜桃综合影院免费观看 | 婷婷午夜天 | 一区二区三区免费观看 | 中文字幕一区二区三区精彩视频 | 最新日韩在线视频 | 亚洲午夜精品一区二区三区他趣 | 看毛片的网站 | 在线观看国产 | 亚洲国产一区二区视频 | 九九国产在线观看 | 亚洲一区三区在线观看 | 91精品国产一区 | 欧美一区二区三区在线观看视频 | 欧美人成在线视频 | 久久国产区 | 成人日b视频 | 综合自拍 | 日本精品裸体写真集在线观看 | 日韩精品一二三区 | 欧美精品在线观看 | 日韩精品免费视频 | 成人精品一区二区户外勾搭野战 | 欧美日韩不卡合集视频 | 中文字幕亚洲区一区二 |