(转)利用libcurl和国内著名的两个物联网云端通讯的例程, ubuntu和openwrt下调试成功(四)

1. libcurl 的参考文档如下

CURLOPT_HEADERFUNCTION

Pass a pointer to a function that matches the following prototype: size_t function( void *ptr, size_t size, size_t nmemb, void *userdata);. This function gets called by libcurl as soon as it has received header data. The header callback will be called once for each header and only complete header lines are passed on to the callback. Parsing headers is very easy using this. The size of the data pointed to by ptr is sizemultiplied with nmemb. Do not assume that the header line is zero terminated! The pointer named userdata is the one you set with the CURLOPT_WRITEHEADER option. The callback function must return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it‘ll signal an error to the library. This will abort the transfer and return CURL_WRITE_ERROR.

A complete HTTP header that is passed to this function can be up to CURL_MAX_HTTP_HEADER (100K) bytes.

If this option is not set, or if it is set to NULL, but CURLOPT_HEADERDATA (CURLOPT_WRITEHEADER) is set to anything but NULL, the function used to accept response data will be used instead. That is, it will be the function specified with CURLOPT_WRITEFUNCTION, or if it is not specified or NULL - the default, stream-writing function.

It‘s important to note that the callback will be invoked for the headers of all responses received after initiating a request and not just the final response. This includes all responses which occur during authentication negotiation. If you need to operate on only the headers from the final response, you will need to collect headers in the callback yourself and use HTTP status lines, for example, to delimit response boundaries.

When a server sends a chunked encoded transfer, it may contain a trailer. That trailer is identical to a HTTP header and if such a trailer is received it is passed to the application using this callback as well. There are several ways to detect it being a trailer and not an ordinary header: 1) it comes after the response-body. 2) it comes after the final header line (CR LF) 3) a Trailer: header among the regular response-headers mention what header(s) to expect in the trailer.

For non-HTTP protocols like FTP, POP3, IMAP and SMTP this function will get called with the server responses to the commands that libcurl sends.

CURLOPT_WRITEHEADER

(This option is also known as CURLOPT_HEADERDATA) Pass a pointer to be used to write the header part of the received data to. If you don‘t use CURLOPT_WRITEFUNCTION or CURLOPT_HEADERFUNCTIONto take care of the writing, this must be a valid FILE * as the internal default will then be a plain fwrite(). See also the CURLOPT_HEADERFUNCTION option above on how to set a custom get-all-headers callback.

2. 完整code如下

点击(此处)折叠或打开

  1. /*------------------------------------------------------------------------------------------
  2. 名称: http_cloud_curl_callbak.c
  3. 利用libcurl的API的回调机制实现云端通讯. http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
  4. CURLOPT_HEADERFUNCTION, CURLOPT_HEADERDATA: 只处理HTTP头部数据,处理与下载数据回调的处理相同.
  5. sina的股票接口因为无HTTP头部返回因此不能应用此.
  6. -------------------------------------------------------------------------------------------*/
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <curl/curl.h>
  11. #include <assert.h>
  12. #include "../http_cloud.h"
  13. #define CURL_HEADER (1)    //0=利用 CURLOPT_WRITEFUNCTION, 1=利用 CURLOPT_HEADERFUNCTION
  14. #define DBG printf
  15. #define CURL_DBG (0)    //1=开启curl的调试
  16. //-----------------------------------------------------------------------------------------
  17. static void get_local_time(char *pc_str)
  18. {
  19. time_t now;
  20. struct tm *timenow;
  21. assert(pc_str != NULL);
  22. time(&now);
  23. timenow = localtime(&now);
  24. sprintf(pc_str, "%04d-%02d-%02dT%02d:%02d:%02d", timenow->tm_year+1900, timenow->tm_mon+1, timenow->tm_mday,
  25. timenow->tm_hour, timenow->tm_min, timenow->tm_sec);
  26. }
  27. size_t callback_get_head(void *ptr, size_t size, size_t nmemb, void *userp)
  28. {
  29. DBG("ptr = %s, userp = %s\n", ptr, userp);
  30. strcat(userp, ptr);
  31. return size * nmemb; //必须返回这个大小, 否则只回调一次
  32. }
  33. static char connect_cloud(char *pc_ret, const char *host_addr, const int portno,
  34. const char *pc_method, struct curl_slist *http_headers)
  35. {
  36. CURL *curl;
  37. CURLcode res = CURLE_GOT_NOTHING;
  38. assert((pc_ret != NULL) && (host_addr != NULL) && (http_headers != NULL) && (pc_method != NULL));
  39. //curl_global_init(CURL_GLOBAL_DEFAULT);
  40. curl = curl_easy_init();
  41. if (!curl)    {
  42. fprintf(stderr, "--- curl init Error!\n");
  43. return 0;
  44. }
  45. curl_easy_setopt(curl, CURLOPT_URL, host_addr);
  46. curl_easy_setopt(curl, CURL_HTTP_VERSION_1_1, 1L);    //HTTP 1.1
  47. curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);     //设置超时, 单位为秒
  48. //curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);     //屏蔽其它信号, makes libcurl NOT ask the system to ignore SIGPIPE signals
  49. #if (CURL_DBG == 1)
  50. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);    //调试用: 显示交互明细,
  51. //curl_easy_setopt(curl, CURLOPT_HEADER, 1L);    //调试用: 只显示头行的返回
  52. #endif
  53. #if 1
  54. curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, pc_method);
  55. #if (CURL_HEADER == 0)
  56. curl_easy_setopt(curl, CURLOPT_HEADER, 1);         //下载数据包括HTTP头部, The default value for this parameter is 0.
  57. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback_get_head); //下载数据的回调函数
  58. curl_easy_setopt(curl, CURLOPT_WRITEDATA, pc_ret);                                //下载数据的指针
  59. #else
  60. curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, callback_get_head); //头部数据的回调函数
  61. curl_easy_setopt(curl, CURLOPT_HEADERDATA, pc_ret);                                //头部数据的指针
  62. #endif
  63. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_headers);    //多行的HTTP头部
  64. #endif
  65. res = curl_easy_perform(curl);
  66. if(res != CURLE_OK)
  67. fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
  68. curl_easy_cleanup(curl);
  69. return 1;
  70. }
  71. #if (YEELINK == 1)
  72. int yeelink_create_data(const int device_id, const int sensor_id, const float device_value)
  73. {
  74. char pc_ret[500], request[1024], pc_json[100], pc_time[30], pc_host_file[100], pc_header[100], pc_url[200], ret;
  75. int len;
  76. sprintf(pc_host_file, "v1.0/device/%d/sensor/%d/datapoints", device_id, sensor_id);
  77. sprintf(pc_header, "U-ApiKey: %s", YEELINK_API_KEY);
  78. get_local_time(pc_time);
  79. sprintf(pc_json, "{\"timestamp\":\"%s\",\"value\":%.2f}", pc_time, device_value);
  80. len = strlen(pc_json);
  81. //sprintf(request, "POST /%s HTTP/1.1\r\nHost: %s\r\nAccept: */*\r\n%s\r\nContent-Length: %d\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: Close\r\n\r\n%s\r\n",
  82. //    pc_host_file, YEELINK_HOST, pc_header, len, pc_json);
  83. //DBG("request = %s\n", request);
  84. //组织请求头部, 自动末尾添加‘\r\n‘
  85. struct curl_slist *http_headers = NULL;
  86. //sprintf(request, "POST /%s HTTP/1.1", pc_host_file);
  87. //http_headers = curl_slist_append(http_headers, request);    //此部分在url中体现
  88. sprintf(request, "Host: %s", YEELINK_HOST);
  89. http_headers = curl_slist_append(http_headers, request);
  90. sprintf(request, "%s", pc_header);
  91. http_headers = curl_slist_append(http_headers, request);
  92. sprintf(request, "%s", "Accept: */*");
  93. http_headers = curl_slist_append(http_headers, request);
  94. sprintf(request, "Content-Length: %d", len);
  95. http_headers = curl_slist_append(http_headers, request);
  96. sprintf(request, "%s", "Content-Type: application/x-www-form-urlencoded");
  97. http_headers = curl_slist_append(http_headers, request);
  98. sprintf(request, "%s", "Connection: Close");
  99. http_headers = curl_slist_append(http_headers, request);
  100. sprintf(request, "\r\n%s", pc_json);
  101. http_headers = curl_slist_append(http_headers, request);
  102. #if 0
  103. struct curl_slist *tmp = http_headers;
  104. printf("HTTP request = ");
  105. while(tmp) {
  106. printf("%s\n", tmp->data);
  107. tmp = tmp->next;
  108. }
  109. #endif
  110. //发送请求, 再判断返回值
  111. //url = api.yeelink.net/v1.0/device/391/sensor/497/datapoints
  112. sprintf(pc_url, "%s/%s", YEELINK_HOST, pc_host_file);
  113. ret = connect_cloud(pc_ret, pc_url, YEELINK_PORT, HTTP_POST, http_headers);
  114. //释放 http_headers资源
  115. curl_slist_free_all(http_headers);
  116. DBG("yeelini ret = %s\n", pc_ret);
  117. return(ret);
  118. }
  119. #endif
  120. #if (LEWEI50 == 1)
  121. //curl --request POST http://www.lewei50.com/api/V1/Gateway/UpdateSensors/01 --data "[{\"Name\":\"T1\",\"Value\":\"23.08\"}]" --header "userkey:36be8ff22f794f1e8a0bee3336eef237"
  122. int lewei50_create_data(const char *device_id, const float device_value)
  123. {
  124. char pc_ret[500], request[1024], pc_json[100], pc_header[100], pc_url[200], *pc_data, ret;
  125. int len;
  126. assert(device_id != NULL);
  127. sprintf(pc_header, "userkey: %s", LEWEI50_USER_KEY);
  128. sprintf(pc_json, "[{\"Name\":\"%s\",\"Value\":\"%.2f\"}]", device_id, device_value);
  129. len = strlen(pc_json);
  130. //sprintf(request, "POST /%s HTTP/1.1\r\nHost: %s\r\nAccept: */*\r\n%s\r\nContent-Length: %d\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: Close\r\n\r\n%s\r\n",
  131. //    LEWEI50_HOST_FILE, LEWEI50_HOST, pc_header, len, pc_json);
  132. //DBG("request = %s\n", request);
  133. //组织请求头部, 自动末尾添加‘\r\n‘
  134. struct curl_slist *http_headers = NULL;
  135. //sprintf(request, "POST /%s HTTP/1.1", pc_host_file);
  136. //http_headers = curl_slist_append(http_headers, request);    //此部分在url中体现
  137. sprintf(request, "Host: %s", LEWEI50_HOST);
  138. http_headers = curl_slist_append(http_headers, request);
  139. sprintf(request, "%s", pc_header);
  140. http_headers = curl_slist_append(http_headers, request);
  141. sprintf(request, "%s", "Accept: */*");
  142. http_headers = curl_slist_append(http_headers, request);
  143. sprintf(request, "Content-Length: %d", len);
  144. http_headers = curl_slist_append(http_headers, request);
  145. sprintf(request, "%s", "Content-Type: application/x-www-form-urlencoded");
  146. http_headers = curl_slist_append(http_headers, request);
  147. sprintf(request, "%s", "Connection: Close");
  148. http_headers = curl_slist_append(http_headers, request);
  149. sprintf(request, "\r\n%s", pc_json);
  150. http_headers = curl_slist_append(http_headers, request);
  151. //发送请求, 再判断返回值
  152. //url = www.lewei50.com/api/V1/gateway/UpdateSensors/01
  153. sprintf(pc_url, "%s/%s", LEWEI50_HOST, LEWEI50_HOST_FILE);
  154. ret = connect_cloud(pc_ret, pc_url, LEWEI50_PORT, HTTP_POST, http_headers);
  155. //释放 http_headers资源
  156. curl_slist_free_all(http_headers);
  157. //{"Successful":true,"Message":"Successful. "}, 模式不同此返回数据的位置也不同.
  158. DBG("lewei50 ret = %s\n", pc_ret);
  159. ret = 0;
  160. pc_data = strstr(pc_ret, HTTP_RET_OK);
  161. if (pc_data) {
  162. pc_data += strlen(HTTP_RET_OK);
  163. //只返回最后的 json数据
  164. pc_data = strstr(pc_data, "\r\n\r\n");
  165. if (pc_data) {
  166. pc_data += 4;
  167. ret = 1;
  168. DBG("lewei50 data = %s\n", pc_data);
  169. }
  170. }
  171. return(ret);
  172. }
  173. #endif
  174. //-------------------------------------------------------------------
  175. int main(void)
  176. {
  177. float f_value = 15.02;
  178. int i_tmp;
  179. time_t t;
  180. srand((unsigned)time(&t));    //初始化随机种子, 否则随机数不随机
  181. i_tmp = rand();
  182. i_tmp -= (i_tmp >> 4 << 4);
  183. f_value += i_tmp;
  184. #if (YEELINK == 1)
  185. yeelink_create_data(YEELINK_DEVICE_ID, YEELINK_SENSOR_ID, f_value);
  186. #endif
  187. #if (LEWEI50 == 1)
  188. lewei50_create_data(LEWEI50_DEVICE_ID, f_value);
  189. #endif
  190. return 1;
  191. }

3.  Makefile如下

点击(此处)折叠或打开

  1. OPENWRT = 1
  2. ifeq ($(OPENWRT), 1)
  3. CC = ~/OpenWrt-SDK-ar71xx-for-linux-i486-gcc-4.6-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc
  4. CFLAGS += -I ~/openwrt-lib/include -L ~/openwrt-lib/lib
  5. LFLAGS += -lcurl -lcrypto -lz -lssl
  6. else
  7. CC = gcc
  8. LFLAGS += -lcurl
  9. endif
  10. CFLAGS += -Wall -O2
  11. #CFLAGS += -g
  12. #可执行文件名和相关的obj文件
  13. APP_BINARY = http_cloud
  14. SRCS += http_cloud_curl_callback.c
  15. OBJS = $(SRCS:.c=.o)
  16. all: APP_FILE
  17. APP_FILE: $(OBJS)
  18. $(CC) $(CFLAGS) $(OBJS) -o $(APP_BINARY) $(LFLAGS)
  19. .PHONY: clean
  20. clean:
  21. @echo "cleanning project"
  22. $(RM) *.a $(OBJS) *~ *.so *.lo $(APP_BINARY)
  23. @echo "clean completed"

4. 运行结果如下
[email protected]:~/1-wire/http_cloud/libcurl$ ./http_cloud
ptr = HTTP/1.1 200 OK
, userp = 
ptr = Server: nginx/1.1.19
, userp = HTTP/1.1 200 OK

ptr = Date: Mon, 25 Nov 2013 01:29:37 GMT
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19

ptr = Content-Type: text/html
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT

ptr = Transfer-Encoding: chunked
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html

ptr = Connection: close
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html
Transfer-Encoding: chunked

ptr = X-Powered-By: PHP/5.3.10-1ubuntu3.6
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close

ptr = Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6

ptr = P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/

ptr = 
, userp = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

yeelini ret = HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

ptr = HTTP/1.1 200 OK
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

ptr = Date: Mon, 25 Nov 2013 01:29:37 GMT
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK

ptr = Content-Type: application/json; charset=utf-8
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT

ptr = Content-Length: 44
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: application/json; charset=utf-8

ptr = Connection: close
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 44

ptr = Cache-Control: private
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 44
Connection: close

ptr = Set-Cookie: SERVERID=a4a5b2bbca16d8c8b2ba6d5b6e55f36e|1385342977|1385342977;Path=/
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 44
Connection: close
Cache-Control: private

ptr = 
, userp = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 44
Connection: close
Cache-Control: private
Set-Cookie: SERVERID=a4a5b2bbca16d8c8b2ba6d5b6e55f36e|1385342977|1385342977;Path=/

{"Successful":true,"Message":"Successful. "}lewei50 ret = onnection: close
X-Powered-By: PHP/5.3.10-1ubuntu3.6
Set-Cookie: CAKEPHP=kgqv6b4rnbbtn1h1ndda514936; expires=Tue, 03-Dec-2013 09:29:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

HTTP/1.1 200 OK
Date: Mon, 25 Nov 2013 01:29:37 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 44
Connection: close
Cache-Control: private
Set-Cookie: SERVERID=a4a5b2bbca16d8c8b2ba6d5b6e55f36e|1385342977|1385342977;Path=/

lewei50 data =

[email protected]:~/1-wire/http_cloud/libcurl$

时间: 2024-09-30 13:49:12

(转)利用libcurl和国内著名的两个物联网云端通讯的例程, ubuntu和openwrt下调试成功(四)的相关文章

针对《谈对国内公有云两个计费现象的思考》的想法

有某AWS专家-原文是"阮志敏, AWS认证架构师(专业级别)"在CSDN上发了一篇文章<谈对国内公有云两个计费现象的思考>http://www.csdn.net/article/2014-08-13/2821180 他说了几点 * IasS没有API -- 本人在XX云时,开发过API服务和几种常用语言的SDK+CLI包,并提供给了少量试用用户.但是纯API是无法立足市场的,必须依托一个良好的.带有UI的集成系统,目前还看不到一个成型的类似产品.RightScale的平台

(转)利用libcurl获取新浪股票接口, ubuntu和openwrt实验成功(三)

1.  利用 CURLOPT_WRITEFUNCTION 设置回调函数, 利用 CURLOPT_WRITEDATA 获取数据指针 官网文档如下 CALLBACK OPTIONS CURLOPT_WRITEFUNCTION Pass a pointer to a function that matches the following prototype: size_t function( char *ptr, size_t size, size_t nmemb, void *userdata); 

国内首篇介绍JanOS物联网操作系统的文章 - 如何把你的手机主板打造成物联网平台

天地会珠海分舵注:如无意外,您现在正在看的将是国内首篇且是唯一一篇介绍炙手可热的物联网的操作系统JanOS的文章!不信你去百度!希望大家能喜欢.但本文只是引言,更多信息请还是访问JanOS的官网:http://janos.io/ JanOS 让你的手机瞬间变身成物联网平台 JanOS是一个设计成运行在你的手机芯片上的操作系统.它可以在没有屏幕的情况下跑起来,让你可以可以通过当今红得发紫的JavaScript的API来访问你的手机的所有功能,从打电话到照相功能无所不包. 你问我在搞毛? 当前炙手可

客户端技术的一点思考(数据存储用SQLite, XMPP通讯用Gloox, Web交互用LibCurl, 数据打包用Protocol Buffer, socket通讯用boost asio)

今天看到CSDN上这么一篇< 彻底放弃没落的MFC,对新人的忠告!>, 作为一个一直在Windows上搞客户端开发的C++程序员,几年前也有过类似的隐忧(参见 落伍的感觉), 现在却有一些不同的想法. 首先,个人职业发展是否成功, 技术只是其中一小块,尤其是在大公司, 更多的是依靠所谓的软实力.作为一个对技术有追求的工匠,我们下面重点说技术相关的. 现在回头看计算机行业的发展,我们看到不同的发展阶段: 1. PC时代,这个时代离我们并不遥远, 也有是2000年前后, 该时代最鲜明的特征是Win

iPhone 和 iPad的ios 开发中 利用 WebViewJavascriptBridge组件,通过 UIWebView 对Html进行双向通讯

本文转载至 http://blog.csdn.net/remote_roamer/article/details/7261490 WebViewJavascriptBridge 项目的 官网 https://github.com/marcuswestin/WebViewJavascriptBridge 主要过程: 下载WebViewJavascriptBridge.h 和 WebViewJavascriptBridge.m文件到自己的项目中,并添加到项目. 在相应的.h文件中 使用#import

利用libcurl进行post

逛百度知道看到有个人提问:http://zhidao.baidu.com/question/1447092283140740700 C写HTTP应用只有疯子才会老老实实的SOCKET编程吧?我后来还是没给他写,因为就算是libcurl我也没下载安装.下面的哥们的用C#几行代码就搞定了,只需引入个类库一切就唾手可得,这就是OOP的好处.后来闲得无聊,还是下载了个libcurl库配置到MinGW中,简单写了个POST的例子. 代码如下: #include <stdio.h> #include &l

.NET中利用反射来实现自动映射两个对象中的数据成员

在以前的项目开发之中,经常会遇到这样一个问题:比如在外面项目的架构设计之中,我们采用MVC和EntityFramework来构建一个Web应用程序.比如我们采用常用的多层架构,例如有Presentation层.BusinessLogic层.DataAccess层等,各层之间是相对独立并且职责分明的.比如我们在Presentation层中会定义ViewModel,在DataAccess层中的DbContext部分又会由EntityFramework来自动生成StorageModel,或者叫做Dat

国内流行的两大开源.net微信公众平台SDK对比分析

最近忙于微信周边的开发 难免手痒去搜索一下有没有相关的sdk直接拿来使 还真发现了不少 这里总结两个看起来比较不错的.net平台下基于C#语言开发的SDK 一个强大一个小巧 (1) Senparc.Weixin.MP Github: https://github.com/JeffreySu/WeiXinMPSDK (Fork:500+) 标语:微信公众平台SDK Senparc.Weixin for C# 达到1000+ commits,15个contributors,5个branches. (

git 利用分支概念实现一个仓库管理两个项目

需求描述:开发了一个网站,上线之际,突然另一个客户说也想要个一样的网站,但网站的logo和内部展示图片需要替换一下,也就是说大部分的后台业务逻辑代码都是一致的,以后升级时功能也要保持一致:刚开始想反正是两个项目,干脆弄两个工程吧,但这样做的话,只有修改个公共的代码逻辑两个项目都要修改一遍,太麻烦了,还容易出错了,太麻烦了,难道没有个好的办法,修改一次代码,两个项目可以共用?突然想到了git的分支概念,我靠~单独再拉出个分支,这不一下就解决了: 前提假设:假设之前开发的网站叫a,另一个客户想要一模