Commit 3ef3d88e authored by captainwong's avatar captainwong

updated curl_wrapper

parent ddd7eb95
#pragma once
#include "../3rdparty/curl/curl.h"
/**
* simple curl wrapper
* under windows, you should config project's include/lib path to your curl-path.
* define CURL_STATICLIB in your prject
* the input libs are: libcurl.lib;ws2_32.lib;wldap32.lib;crypt32.lib;
*/
#include <curl/curl.h>
#include <string>
#include "mem_tool.h"
namespace jlib
{
class Curl
struct CurlHelper {
CurlHelper() {
curl_global_init(CURL_GLOBAL_ALL);
}
~CurlHelper() {
curl_global_cleanup();
}
};
struct Curl
{
public:
Curl() { static CurlHelper helper = {}; }
~Curl() {
......@@ -79,16 +96,8 @@ public:
}
#endif // JLIB_LOG2_ENABLED
private:
struct CurlHelper {
CurlHelper() {
curl_global_init(CURL_GLOBAL_ALL);
}
~CurlHelper() {
curl_global_cleanup();
}
};
///////////////////////////// details ///////////////////////////////
CURL* curl_ = nullptr;
std::string buffer_ = {};
......
#include "../../jlib/util/curl_wrapper.h"
#include <stdio.h>
#ifdef _WIN32
#pragma comment(lib, "../../jlib/3rdparty/curl/libcurldll.a")
#endif
using namespace jlib;
......@@ -11,7 +8,9 @@ int main()
{
Curl curl;
curl.init();
curl.get("qq.com");
curl.get("https://baidu.com");
printf("HTTP %ld\n", curl.lastHttpCode());
printf("error %d\n", curl.lastError());
printf("error msg %s\n", curl.lastErrorMsg().data());
printf("%s\n", curl.lastHttpContent().data());
}
......@@ -76,9 +76,13 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(DEVLIBS)\curl-7.66.0\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>CURL_STATICLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>$(DEVLIBS)\curl-7.66.0\build\Win32\VC15\LIB Release - DLL Windows SSPI;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libcurl.lib;ws2_32.lib;wldap32.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment