Mongoose库使用起来非常简单,只有2个文件,一个.h 一个.cpp,添加到项目中,就可以使用了
Mongoose的项目地址是 https://github.com/cesanta/mongoose
1. 配置HTTPS支持,需要使用OpenSSL库,如果不想编译,可以到这里http://slproweb.com/products/Win32OpenSSL.html,下载预编译包,这里的预编译包使用VS2017编译的。
2. 我之前很早下载过OpenSSL的预编译包,是VS2013编译的,如果当前编译器不是VS2013,在编译程序时会有问题
3. 代码,增加 #define MG_ENABLE_SSL 1
4. 配置OpenSSL ,在mongoose.c中,4474行后,增加
#pragma comment(lib,"libeay32MTd.lib")
#pragma comment(lib,"ssleay32MTd.lib")
5. 项目工程配置OpenSSL的头文件
6. 因为我的当前项目是VS2015,OpenSSL的是VS2013,有错误,增加代码
#if _MSC_VER>=1900 #include "stdio.h" _ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned); #ifdef __cplusplus extern "C" #endif FILE* __cdecl __iob_func(unsigned i) { return __acrt_iob_func(i); } #endif /* _MSC_VER>=1900 */
7. 再次编译项目,即可