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

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

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

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

      1. <tfoot id='V5Qtt'></tfoot>

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

        時間:2019-05-16 標簽:c++libcurljsonrest

        c++ libcurl json rest(時間:2019-05-16 標簽:c++libcurljsonrest)
          <bdo id='vRRA6'></bdo><ul id='vRRA6'></ul>
            1. <legend id='vRRA6'><style id='vRRA6'><dir id='vRRA6'><q id='vRRA6'></q></dir></style></legend>
                <tbody id='vRRA6'></tbody>

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

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

                • <tfoot id='vRRA6'></tfoot>
                  本文介紹了時間:2019-05-16 標簽:c++libcurljsonrest的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 libcurl 從 C++ 中的 REST 網頁下載 json 文件.如果我轉到網頁,以下代碼有效,但如果我嘗試訪問 json 則無法下載....

                  I am trying to download a json file from a REST webpage in C++ with libcurl. The following code works if I go to the webpage but it doesnt download if I try to access the json ....

                  我認為這應該是一個簡單的修復,但我找不到任何對此的參考......

                  I think it should be an easy fix but I cant find any reference to this ...

                  如果我轉到網頁,它會打開 json 但此代碼僅返回 text/html;字符集=utf-8

                  If I go to webpage it opens the json but this code only returns text/html; charset=utf-8

                  ??????????

                  CURL *curl;
                  CURLcode res;
                      struct curl_slist *headers=NULL; // init to NULL is important 
                      headers = curl_slist_append(headers, "Accept: application/json");   
                  
                  curl = curl_easy_init();
                  if(curl) {
                  
                      curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/api/json/123");
                              curl_easy_setopt(curl, CURLOPT_HTTPGET,1);
                      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
                      //curl_easy_setopt(curl, CURLOPT_URL, "http://web.com/123.html");//this works!!!
                      res = curl_easy_perform(curl);
                  
                      if(CURLE_OK == res) {
                          char *ct;
                          /* ask for the content-type */
                          res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
                          if((CURLE_OK == res) && ct)
                              printf("We received Content-Type: %s
                  ", ct);
                      }
                  }
                  /* always cleanup */ 
                  curl_easy_cleanup(curl);
                  

                  推薦答案

                  std::string ServerContent::DownloadJSON(std::string URL)
                  {   
                      CURL *curl;
                      CURLcode res;
                      struct curl_slist *headers=NULL; // init to NULL is important 
                      std::ostringstream oss;
                      headers = curl_slist_append(headers, "Accept: application/json");  
                      headers = curl_slist_append(headers, "Content-Type: application/json");
                      headers = curl_slist_append(headers, "charset: utf-8"); 
                      curl = curl_easy_init();
                  
                      if (curl) 
                      {
                          curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
                          curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());
                          curl_easy_setopt(curl, CURLOPT_HTTPGET,1); 
                          curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,writer);
                          res = curl_easy_perform(curl);
                  
                          if (CURLE_OK == res) 
                          { 
                              char *ct;         
                              res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
                              if((CURLE_OK == res) && ct)
                                  return *DownloadedResponse;
                          }
                      }
                  
                      curl_slist_free_all(headers);
                  }
                  
                  
                  static std::string *DownloadedResponse;
                  
                  static int writer(char *data, size_t size, size_t nmemb, std::string *buffer_in)
                  {
                  
                      // Is there anything in the buffer?  
                      if (buffer_in != NULL)  
                      {
                          // Append the data to the buffer    
                          buffer_in->append(data, size * nmemb);
                  
                          // How much did we write?   
                          DownloadedResponse = buffer_in;
                  
                          return size * nmemb;  
                      }
                  
                      return 0;
                  
                  }   
                  

                  這篇關于時間:2019-05-16 標簽:c++libcurljsonrest的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 之間的區別)

                      <tbody id='91x2O'></tbody>

                    <small id='91x2O'></small><noframes id='91x2O'>

                  • <legend id='91x2O'><style id='91x2O'><dir id='91x2O'><q id='91x2O'></q></dir></style></legend>

                    <tfoot id='91x2O'></tfoot>
                  • <i id='91x2O'><tr id='91x2O'><dt id='91x2O'><q id='91x2O'><span id='91x2O'><b id='91x2O'><form id='91x2O'><ins id='91x2O'></ins><ul id='91x2O'></ul><sub id='91x2O'></sub></form><legend id='91x2O'></legend><bdo id='91x2O'><pre id='91x2O'><center id='91x2O'></center></pre></bdo></b><th id='91x2O'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='91x2O'><tfoot id='91x2O'></tfoot><dl id='91x2O'><fieldset id='91x2O'></fieldset></dl></div>

                          • <bdo id='91x2O'></bdo><ul id='91x2O'></ul>
                            主站蜘蛛池模板: 91精品国产综合久久婷婷香蕉 | 国产精品一区二区视频 | www.久草| 国产欧美日韩在线观看 | 福利久久 | 不卡视频在线 | 国产99视频精品免费播放照片 | 国产1区2区 | 国产精品不卡 | 亚洲日本中文 | 亚洲精品一区二三区不卡 | 天天爱天天操 | 精品久久香蕉国产线看观看亚洲 | 涩涩视频网站在线观看 | 九色国产 | 亚洲欧美日韩精品久久亚洲区 | 在线观看av网站 | 综合自拍| 狠狠入ady亚洲精品经典电影 | 国产一区| 成人在线观看免费 | 最新超碰 | 久久精品国产一区二区三区 | 999久久久免费精品国产 | 国产精品美女www | 天堂成人国产精品一区 | 中文字幕亚洲国产 | 午夜不卡一区二区 | 午夜视频在线免费观看 | 日日操日日舔 | 99在线资源| 国产精品一区二区日韩 | 久久99精品国产 | 欧美精品三区 | 午夜视频大全 | 福利视频1000| 日韩视频在线一区 | 韩国主播午夜大尺度福利 | 二区三区视频 | 秋霞精品 | 中文字幕亚洲精品 |