当前位置: 技术问答>linux和unix
libcurl问题
来源: 互联网 发布时间:2016-10-10
本文导语: 用libcurl访问mezeo的webservice, 我看它的API上有一个example是这样写的: Example curl command: curl -u $cred -H ‘X-Client-Specification: 2’ –H ‘X-Cloud-Key: $Key’ -X GET https://api.example.com/v2 | xml fo 现在它给的是用命令...
用libcurl访问mezeo的webservice, 我看它的API上有一个example是这样写的:
Example curl command:
curl -u $cred -H ‘X-Client-Specification: 2’ –H ‘X-Cloud-Key: $Key’
-X GET https://api.example.com/v2 | xml fo
现在它给的是用命令行的方式来发送请求,我现在用程序来发送请求,用的libcurl库该怎么实现啊?
Example curl command:
curl -u $cred -H ‘X-Client-Specification: 2’ –H ‘X-Cloud-Key: $Key’
-X GET https://api.example.com/v2 | xml fo
现在它给的是用命令行的方式来发送请求,我现在用程序来发送请求,用的libcurl库该怎么实现啊?
|
自己看看例子不好么:
发送的信息为:
#include
#include
int
main(int argc, char *argv[])
{
CURL *handle;
char url[] = "http://127.0.0.1:20001";
struct curl_slist *slist;
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url);
slist = NULL;
slist = curl_slist_append(slist, "X-Client-Specification: 2");
slist = curl_slist_append(slist, "X-Cloud-Key: 0123456789ABCDEF");
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
curl_easy_perform(handle);
curl_slist_free_all(slist);
return 0;
}
发送的信息为:
GET / HTTP/1.1
Host: 127.0.0.1:20001
Pragma: no-cache
Accept: */*
X-Client-Specification: 2
X-Cloud-Key: 0123456789ABCDEF
]