
libfetch.h以下均以QT4.8.5为例1.将libfetch.so复制到虚拟机的/usr/local/Trolltech/Qt-4.8.7/lib和设备的/opt/qt4.8.5/lib两个目录下qt4。2.将libfetch.h复制到qt工程的头文件目录中。3.修改.pro工程文件添加LIBS lfetch4.示例代码libfetch.h#ifndef LIBFETCH_H #define LIBFETCH_H #ifdef __cplusplus extern C { #endif extern char* FetchHTTPS(char* method, char* url, char* certFile, char* data, char** headers, int headerCount); extern void FreeString(char* str); #ifdef __cplusplus } #endif #endiflibfetch.cpp#include stdio.h #include libfetch.h int main() { char* url https://uniapi.yunwuyun.com/api/getToken; char* certFile ca.crt; char* method POST; char* headers[] { Content-Type: application/json, uniapi-secret: on6UaoA1rk69DWJtVsuHf6/gvePBjexpcw9IPirCyocPMoFsctKUenmsjde37EMql2bKIDGnn3x50bOtrZw5ZQ }; char* resp FetchHTTPS(method,url,certFile,,headers,2); printf(\nURL:%s\n, url); printf(-------------------------------------------------------\n); printf(Response: %s\n, resp); FreeString(resp); url https://www.baidu.com; certFile baidu.crt; method GET; resp FetchHTTPS(method,url,certFile,,headers,0); printf(\nURL:%s\n, url); printf(-------------------------------------------------------\n); printf(Response: %s\n, resp); FreeString(resp); url https://jsonplaceholder.typicode.com/posts; certFile typicode.crt; method POST; char *data {\title\: \Hello\,\body\: \This is a test post\,\userId\: 7}; char* headers1[] { Content-Type: application/json, }; resp FetchHTTPS(method,url,certFile,data,headers1,1); printf(\nURL:%s\n, url); printf(-------------------------------------------------------\n); printf(Response: %s\n, resp); FreeString(resp); return 0; }