300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > c语言 Linux CURL发送Http get请求 带参数

c语言 Linux CURL发送Http get请求 带参数

时间:2021-12-11 16:15:43

相关推荐

c语言 Linux CURL发送Http get请求 带参数

我要请求的是

/ccic-fs/IOT/updateData.shtml?sn=111111111&dataTime=-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"]

转义后

/ccic-fs/IOT/updateData.shtml?sn=111111111&dataTime=-01-24%: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 - , Daniel Stenberg, <daniel@haxx.se>, 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, "/ccic-fs/IOT/updateData.shtml?sn=111111111&dataTime=-01-24%: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","采集时间:-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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。