原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/2019/0914/641.html
一、环境win7 64位 vs2010
二、文件准备:
2.1文件下载
libcurl 下载页面: http://curl.haxx.se/download.html (我App开发培训下载的是https://curl.haxx.se/download/curl-7.50.3.zip)
openssl 下载页面:http://www.openssl.org/source (我下载的是openssl-1.0.1u)
ActivePerl(编译openssl时要用) 下载页面 http://www.activestate.com/activeperl/downloads 依据本人的需求选择64位或32位
2.2文件解压及装置
ActivePerl装置,双击直接下一步,默许设置到底。
openssl、 libcurl分别解压,将他们放在同一级目录。 例如:“D:\TestCurl\curl-7.50.3”、“D:\TestCurl\openssl-1.0.1u”
三、编译过程:
3.1 openssl编译
运用VS2010下的Visual Studio 2010 Command Prompt进入控制台形式 (开端菜单->一切程序->Microsoft->Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio 2010 Command Prompt)
进入openssl源码的目录
命令行键入:d:
命令行键入:cd D:\TestCurl\openssl-1.0.1u //把途径交换成本人的源码途径
3. 命令行键入:perl configure VC-WIN32
4. 命令行键入:ms\do_ms.bat
5. 编译分两种状况,生成静态库和动态库
(1) 假如常州网站开发培训是编译OpenSSL动态库,则在命令行键入:nmake -f ms\ntdll.mak
(编译胜利在文件夹out32dll里面生成输出文件,包括应用程序的exe文件、lib文件、dll文件。)
(2) 假如是编译OpenSSL静态库,则在命令行键入:nmake -f ms\nt.mak
(编译胜利在文件夹out32里面生成输出文件,包括应用程序的exe文件、lib文件。)
留意:此处编译需求较长时间,请耐烦等候,切勿人为中缀。
到此编译曾经完成,将OpenSSL下的include文件夹、lib文件、dll文件考出,运用的时分包含进去就行了。
另外还有几个命令可能会用到:
测试OpenSSL动态库:nmake -f ms\ntdll.mak test
测试OpenSSL静态库:nmake -f ms\nt.mak test
装置OpenSSL动态库:nmake -f ms\ntdll.mak install
装置OpenSSL静态库:nmake -f ms\nt.mak install
肃清上次OpenSSL动态库的编译,以便重新编译:nmake -f ms\ntdll.mak clean
肃清上次OpenSSL静态库的编译,以便重新编译:nmake -f ms\nt.mak clean
3.2 libcurl编译
在 “D:\TestCurl\curl-7.50.3/lib” 目录下新建release.bat,
输入以下内容:
call "C:/Program Files/Microsoft Visual Studio 10.0/VC/bin/vcvars32.bat" //途径为vs2010装置目录
set CFG=release-dll-ssl-dll
set OPENSSL_PATH=../../openssl-1.0.1u
nmake -f Makefile.vc10
保管,然后运转。 等候一会儿,就能够到 curl-7.53.0\lib\release-dll-ssl-dll 目录下拷文件 libcurl_imp.lib和libcurl.dll 啦!
四、运用常州软件技术培训curl库发送https恳求
翻开vs2010新建一个控制台程序
设置工程属性
2.1设置附加包含目录途径为 "D:\TestCurl\curl-7.50.3\include" (或者新建一个文件夹将"D:\TestCurl\curl-7.50.3\include"中的文件拷进去,并将该文件夹途径设置为附加包含目录途径.
2.2 设置链接库器的附加库目录途径
新建一个文件夹将编译libcurl生成的libcurl_imp.lib还有编译openssl生成的libeay32.lib,ssleay32.lib拷进去,并将该文件夹途径设置为附加包含目录途径.
2.3 添加链接器的附加库依赖项 ws2_32.lib、wldap32.lib
2.4添加dll :在输出可执行文件*.exe的途径中添加编译libcurl生成的libcurl.dll以及编译openssl生成的libeay32.dll、ssleay32.dll.
3.代码
#include "stdafx.h"
#include <curl/curl.h>
#pragma comment(lib,"libcurl.lib")
int _tmain(int argc, _TCHAR* argv[])
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, true);
curl_easy_setopt(curl, CURLOPT_URL, "https://mail.qq.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
4.结果
上篇:上一篇:MFC之ListCtrl动态添加按钮
下篇:下一篇:C++用curl库字节流方式以输送https同步Req