c语言中怎么使用HTTP代理

如何再c语言代码中使用http代理ip。
以下代码主要围绕第一次接触http代理ip的c新手来写(步骤注释清晰)。
直接把下面示例代码中的http代理api,替换成你后台生成的代理api链接,就可以跑起来了。
以下是一个示例代码,只是一个基础的演示,具体的代码还是要根据你业务的实际情况去写的。
示例代码中的http代理ip,我使用的是华益云的http代理api,注册就白嫖1万个高匿爬虫ip,有效期是一年,对于调试代码来说这个时间是非常的友好。
示例代码demo中同款http代理api-点我免费领取10000个高匿ip
打开代理api,获取里面的ip,使用ip访问目标网站,其实代码中就是执行这个过程而已,然后加了几个错误判断有助于代码的稳定运行。(步骤注释清晰)
// demo.cpp : 定义控制台应用程序的入口点。//#include stdafx.h#include curl/curl.h#include #include #pragma comment(lib, libcurl.lib)static size_t write_buff_data(char *buffer, size_t size, size_t nitems, void *outstream){ memcpy(outstream, buffer, nitems*size); return nitems*size;}/*使用http代理*/int geturlhttp(char *url, char *buff, char* ip){ curl *curl; curlcode res; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, curlopt_proxy, ip); //代理方式 http://ip:port curl_easy_setopt(curl, curlopt_writedata, (void*)buff);//获得访问结果 curl_easy_setopt(curl, curlopt_writefunction, write_buff_data); curl_easy_setopt(curl, curlopt_url, url); curl_easy_setopt(curl, curlopt_low_speed_time, 10l); curl_easy_setopt(curl, curlopt_low_speed_limit, 50l); curl_easy_setopt(curl, curlopt_max_recv_speed_large, 2000000l);/*下载最高速度*/ res = curl_easy_perform(curl); curl_easy_cleanup(curl); if (res == curle_ok) { return res; } else { printf(错误代码:%d\n, res); messagebox(null, text(获取ip错误), text(助手), mb_iconinformation | mb_yesno); } } return res;}//不使用代理int geturl(char *url, char *buff){ curl *curl; curlcode res; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, curlopt_writedata, (void*)buff); curl_easy_setopt(curl, curlopt_writefunction, write_buff_data); curl_easy_setopt(curl, curlopt_url, url);/*访问url*/ curl_easy_setopt(curl, curlopt_low_speed_time, 10l); curl_easy_setopt(curl, curlopt_low_speed_limit, 50l); curl_easy_setopt(curl, curlopt_max_recv_speed_large, 2000000l);/*下载最高速度*/ res = curl_easy_perform(curl); curl_easy_cleanup(curl); if (res == curle_ok) { return res; } else { printf(错误代码:%d\n, res); messagebox(null, text(获取ip错误), text(助手), mb_iconinformation | mb_yesno); } } return res;}//将utf-8转为gbk格式void utf8togbk(char *utf8string, char *gbkstring){ wchar_t *unicodestr = null; int nretlen = 0; nretlen = multibytetowidechar(cp_utf8, 0, utf8string, -1, null, 0);//求需求的宽字符数大小 unicodestr = (wchar_t *)malloc(nretlen * sizeof(wchar_t)); nretlen = multibytetowidechar(cp_utf8, 0, utf8string, -1, unicodestr, nretlen);//将utf-8编码转换成unicode编码 nretlen = widechartomultibyte(cp_acp, 0, unicodestr, -1, null, 0, null, 0);//求转换所需字节数 nretlen = widechartomultibyte(cp_acp, 0, unicodestr, -1, gbkstring, nretlen, null, 0);//unicode编码转换成gbk编码 free(unicodestr);}int main(){ char *buff = (char*)malloc(1024 * 1024); memset(buff, 0, 1024 * 1024); //代理api(这里我推荐使用www.9vps.com华益云的http代理api,注册就白嫖1万ip) geturl(http://http.9vps.com/getip.asp?username=166xxxx6597&pwd=xxxxbaa59ce237dff65134984b9cxxxx&geshi=1&fenge=1&fengefu=&contenttype=1&getnum=20&setcity=&operate=all&, buff); printf(代理ip列表:\n%s, buff); //输出 //输入代理ip char ip[100]; printf(\nenter your ip:); scanf_s(%s, &ip, 100); //使用代理ip访问网站 memset(buff, 0, 1024 * 1024); geturlhttp(http://myip.top, buff, (char*)ip); utf8togbk(buff, buff);//将获取到的网页内容转为gbk格式 printf(\nhttp结果:%s\n, buff);//输出访问结果 //不使用代理访问 geturl(http://myip.top, buff); utf8togbk(buff, buff); // 将获取到的网页内容转为gbk格式 printf(不使用代理:%s \n, buff);//输出访问结果 sleep(1000 * 1000); free(buff); return 0;}
Docker使用的优点和十一条使用守则的详细概述
ubuntu系统命令大全
关于讯飞智能硬件解决方案发布会的分析和介绍
柴油发电机中性点接地电阻柜的特点介绍
鹏鼎控股6月合并营业17.06亿元!
c语言中怎么使用HTTP代理
MEMS光开关简介
2020年开源软件供应链下一代网络攻击大规模激增430%
用于模拟深度学习应用的质子可编程设备
航天GPS接收机的低噪声放大器设计
艾德克斯(ITECH)亮相慕尼黑上海电子展,引领测试新科技
关于iPhone 7和7 Plus黑色款出现掉漆的问题,官方这样回应
车载DC/DC变换器的指标有哪些
边缘计算的应用场景介绍(边缘计算在哪些领域能得到应用)
Salesforce AppExchange推出了语音数据控制器
区块链可能不是解决工业物联网安全的最好选择
多通道振弦数据记录仪应用桥梁安全监测的解决方案
5G物联网时代来临,移为通信有望继续保持优势身位
LCD投影到了去伪存真时刻,微果Y1重塑新生代投影标杆
工业交换机的工作原理 工业交换机的主要功能