客户端只需要将url由http
变成https
。
如果服务端不是CA认证,那么会请求失败,需要加上两行代码,不是CA认证也正常访问
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#include <stdio.h>
#include <curl/curl.h>
#include <stdlib.h>
//https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443
int main(void)
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_URL, "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "tel=15850781443");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
system("pause");
}
return 0;
}