libcurl客户端发送https请求

客户端只需要将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;
}
未经允许不得转载:紫竹林-程序员中文网 » libcurl客户端发送https请求
关于我们 免责申明 意见反馈 隐私政策
程序员中文网:公益在线网站,帮助学习者快速成长!
关注微信

微信扫码
关注微信

技术交流群
管理员微信号
每天精选资源文章推送
管理员QQ
随时随地碎片化学习
管理员抖音号
发现有趣的