This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
5,603 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "server.h" | ||
namespace Server { | ||
size_t receive_data(void* contents, size_t size, size_t nmemb, void* stream) { | ||
std::string* str = (std::string*)stream; | ||
(*str).append((char*)contents, size * nmemb); | ||
return size * nmemb; | ||
} | ||
CURLcode HttpGet(const std::string& strUrl, std::string& strResponse, | ||
std::string header, int nTimeout) { | ||
CURLcode res; | ||
CURL* pCURL = curl_easy_init(); | ||
if (pCURL == NULL) { | ||
return CURLE_FAILED_INIT; | ||
} | ||
struct curl_slist* headers = NULL; | ||
headers = curl_slist_append(headers, (char*)header.c_str()); | ||
curl_easy_setopt(pCURL, CURLOPT_HTTPHEADER, headers); | ||
curl_easy_setopt(pCURL, CURLOPT_URL, strUrl.c_str()); | ||
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | ||
curl_easy_setopt(pCURL, CURLOPT_NOSIGNAL, 1L); | ||
curl_easy_setopt(pCURL, CURLOPT_TIMEOUT, nTimeout); | ||
curl_easy_setopt(pCURL, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_easy_setopt(pCURL, CURLOPT_NOPROGRESS, 1L); | ||
curl_easy_setopt(pCURL, CURLOPT_WRITEFUNCTION, receive_data); | ||
curl_easy_setopt(pCURL, CURLOPT_WRITEDATA, (void*)&strResponse); | ||
res = curl_easy_perform(pCURL); | ||
curl_easy_cleanup(pCURL); | ||
return res; | ||
} | ||
|
||
CURLcode HttpPost(const std::string& strUrl, std::string header, | ||
std::string szJson, std::string& strResponse, int nTimeout) { | ||
CURLcode res; | ||
CURL* pCURL = curl_easy_init(); | ||
struct curl_slist* headers = NULL; | ||
if (pCURL == NULL) { | ||
return CURLE_FAILED_INIT; | ||
} | ||
CURLcode ret; | ||
ret = curl_easy_setopt(pCURL, CURLOPT_URL, strUrl.c_str()); | ||
// std::string data = curl_easy_escape(pCURL, szJson.c_str(), | ||
// szJson.size()); | ||
std::string data = szJson; | ||
ret = curl_easy_setopt(pCURL, CURLOPT_POST, 1L); | ||
// headers = curl_slist_append(headers, "expect: "); | ||
headers = curl_slist_append(headers, "Accept: application/json"); | ||
headers = curl_slist_append(headers, | ||
"Content-Type: application/json"); // text/html | ||
headers = curl_slist_append(headers, "charsets: utf-8"); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_HTTPHEADER, headers); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_POSTFIELDS, data.c_str()); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_TIMEOUT, 60); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_NOSIGNAL, 1); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_TIMEOUT_MS, 60000); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_SSL_VERIFYPEER, false); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_NOPROGRESS, 1L); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_WRITEFUNCTION, receive_data); | ||
ret = curl_easy_setopt(pCURL, CURLOPT_WRITEDATA, (void*)&strResponse); | ||
res = curl_easy_perform(pCURL); | ||
curl_slist_free_all(headers); | ||
curl_easy_cleanup(pCURL); | ||
return res; | ||
} | ||
|
||
} // namespace Server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#include "head.h" | ||
#include "libcurl/libcurl.h" | ||
namespace Server { | ||
CURLcode HttpPost(const std::string& strUrl, std::string header, | ||
std::string szJson, std::string& strResponse, int nTimeout); | ||
CURLcode HttpGet(const std::string& strUrl, std::string& strResponse, | ||
std::string header, int nTimeout); | ||
} // namespace Server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# include | ||
|
||
Public include files for libcurl, external users. | ||
|
||
They're all placed in the curl subdirectory here for better fit in any kind of | ||
environment. You must include files from here using... | ||
|
||
#include <curl/curl.h> | ||
|
||
... style and point the compiler's include path to the directory holding the | ||
curl subdirectory. It makes it more likely to survive future modifications. | ||
|
||
The public curl include files can be shared freely between different platforms | ||
and different architectures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
curlver.h.dist | ||
stamp-h2 | ||
stamp-h3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#*************************************************************************** | ||
# _ _ ____ _ | ||
# Project ___| | | | _ \| | | ||
# / __| | | | |_) | | | ||
# | (__| |_| | _ <| |___ | ||
# \___|\___/|_| \_\_____| | ||
# | ||
# Copyright (C) 1998 - 2020, Daniel Stenberg, <[email protected]>, et al. | ||
# | ||
# This software is licensed as described in the file COPYING, which | ||
# you should have received as part of this distribution. The terms | ||
# are also available at https://curl.se/docs/copyright.html. | ||
# | ||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell | ||
# copies of the Software, and permit persons to whom the Software is | ||
# furnished to do so, under the terms of the COPYING file. | ||
# | ||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
# KIND, either express or implied. | ||
# | ||
########################################################################### | ||
pkginclude_HEADERS = \ | ||
curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \ | ||
typecheck-gcc.h system.h urlapi.h options.h | ||
|
||
pkgincludedir= $(includedir)/curl | ||
|
||
CHECKSRC = $(CS_$(V)) | ||
CS_0 = @echo " RUN " $@; | ||
CS_1 = | ||
CS_ = $(CS_0) | ||
|
||
checksrc: | ||
$(CHECKSRC)@PERL@ $(top_srcdir)/lib/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS) | ||
|
||
if CURLDEBUG | ||
# for debug builds, we scan the sources on all regular make invokes | ||
all-local: checksrc | ||
endif |
Oops, something went wrong.