c語言 Linux CURL發送Http get請求 帶參數

我要請求的是

http://fs.ccic365.com/ccic-fs/IOT/updateData.shtml?sn=111111111&dataTime=2019-01-24 10:45:04&dataList=["1_1_25.44;25.00;21.32;134","2_1_8.51","3_1_6","4_1_85.44;25.00","5_1_8.52","6_1_8.53;34","7_1_8.54;16.33;33;22","8_1_8.55"]

轉義後

 http://fs.ccic365.com/ccic-fs/IOT/updateData.shtml?sn=111111111&dataTime=2019-01-24%2010:45:04&dataList=[%221_1_25.44;25.00;21.32;134%22,%222_1_8.51%22,%223_1_6%22,%224_1_85.44;25.00%22,%225_1_8.52%22,%226_1_8.53;34%22,%227_1_8.54;16.33;33;22%22,%228_1_8.55%22] 

/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2018, Daniel Stenberg, <[email protected]>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.haxx.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/
/* <DESC>
 * Use getinfo to get content-type after completed transfer.
 * </DESC>
 */
#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://fs.ccic365.com/ccic-fs/IOT/updateData.shtml?sn=111111111&dataTime=2019-01-24%2010:45:04&dataList=[%221_1_25.44;25.00;21.32;134%22,%222_1_8.51%22,%223_1_6%22,%224_1_85.44;25.00%22,%225_1_8.52%22,%226_1_8.53;34%22,%227_1_8.54;16.33;33;22%22,%228_1_8.55%22]");
    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\n", ct);
    }

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

返回正確:

lgl@lgl-virtual-machine:~/Desktop/hello$ ./out
{"數據分析":["主副設備編號:111111111","採集時間:2019-01-24 10:45:04","空氣溫度:25.44℃","空氣溼度:25.00%","二氧化碳濃度:21.32ppm","大氣壓:134pa","風速:8.51m/s","風向:6","土壤溫度:85.44℃","土壤溼度:25.00%","鹽分:8.52%","pm2.5:8.53μg/m3","pm10:34μg/m3","當前雨量:8.54ml","昨日雨量:16.33ml","瞬時雨量:33ml","累積雨量:22ml","光照傳感器:8.55KLUX"],"status":"1"}We received Content-Type: application/json;charset=UTF-8
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章