2#define WIN32_LEAN_AND_MEAN
6#include "../IBaseApi.h"
12#include <Poco/Net/HTTPSClientSession.h>
13#include <Poco/Net/HTTPRequest.h>
14#include <Poco/Net/HTTPResponse.h>
15#include <Poco/StreamCopier.h>
18#include <Poco/Exception.h>
19#include <Poco/UTF8String.h>
20#include <Poco/NullStream.h>
21#include <Poco/Net/SSLManager.h>
22#include <Poco/Net/InvalidCertificateHandler.h>
23#include <Poco/Net/RejectCertificateHandler.h>
33 const std::vector<
std::string>& headers,
const std::string& request_type);
80 const std::vector<
std::string>& headers,
const std::string& request_type)
95 for (
const auto& header : headers)
97 const std::string& key = header.substr(0, header.find(
":"));
98 const std::string& data = header.substr(header.find(
":") + 1);
100 request.add(key, data);
109 std::string result =
"";
115 std::ostringstream oss;
116 Poco::StreamCopier::copyStream(rs, oss);
130 std::vector<
std::string> headers)
132 std::thread([
this, url, callback, headers]
134 std::string Result =
"";
163 const std::string& post_data,
std::vector<
std::string> headers)
165 std::thread([
this, url, callback, post_data, headers]
167 std::string Result =
"";
175 request.setContentType(
"application/x-www-form-urlencoded");
179 OutputStream << post_data;
201 const std::string& post_data,
const std::string& content_type,
std::vector<
std::string> headers)
203 std::thread([
this, url, callback, post_data, content_type, headers]
205 std::string Result =
"";
213 request.setContentType(content_type);
217 OutputStream << post_data;
239 const std::vector<
std::string>& post_ids,
240 const std::vector<
std::string>& post_data,
std::vector<
std::string> headers)
242 if (post_ids.size() != post_data.size())
245 std::thread([
this, url, callback, post_ids, post_data, headers]
247 std::string Result =
"";
257 for (size_t i = 0; i < post_ids.size(); ++i)
259 const std::string& id = post_ids[i];
260 const std::string& data = post_data[i];
267 request.setContentType(
"application/x-www-form-urlencoded");
271 OutputStream << body;
293 std::vector<
std::string> headers)
295 std::thread([
this, url, callback, headers]
297 std::string Result =
"";
334 for (
const auto& request : requests_temp) { request
.callback(request
.success, request.result
); }
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
void WriteRequest(std::function< void(bool, std::string)> callback, bool success, std::string result)
std::string GetResponse(Poco::Net::HTTPClientSession *session, Poco::Net::HTTPResponse &response)
Poco::Net::HTTPRequest ConstructRequest(const std::string &url, Poco::Net::HTTPClientSession *&session, const std::vector< std::string > &headers, const std::string &request_type)
std::vector< RequestData > RequestsVec_
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::vector< std::string > &post_ids, const std::vector< std::string > &post_data, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
static ARK_API Requests & Get()
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, const std::string &content_type, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
std::unique_ptr< impl > pimpl
virtual void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback)=0
Added function will be called every frame.
virtual bool RemoveOnTickCallback(const FString &id)=0
Removes a on-tick callback.
static std::shared_ptr< spdlog::logger > & GetLog()
std::string displayText() const
Returns the exception code if defined.
virtual std::istream & receiveResponse(HTTPResponse &response)
virtual std::ostream & sendRequest(HTTPRequest &request)
Returns the connection timeout for HTTP connections.
static const std::string HTTP_1_1
void setContentLength(std::streamsize length)
Returns the HTTP version for this message.
HTTPRequest(const std::string &method, const std::string &uri, const std::string &version)
Creates a HTTP/1.0 request with the given method and URI.
static const std::string HTTP_GET
static const std::string HTTP_DELETE
static const std::string HTTP_POST
const std::string & getReason() const
Sets the HTTP reason phrase.
HTTPResponse(HTTPStatus status)
HTTPStatus getStatus() const
HTTPSClientSession(const std::string &host, Poco::UInt16 port=HTTPS_PORT)
RejectCertificateHandler(bool handleErrorsOnServerSide)
void initializeClient(PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext)
static SSLManager & instance()
This stream discards all characters written to it.
static std::streamsize copyStream(std::istream &istr, std::ostream &ostr, std::size_t bufferSize=8192)
const std::string & getHost() const
Sets the user-info part of the URI.
const std::string & getScheme() const
URI(const std::string &uri)
Creates an empty URI.
unsigned short getPort() const
Sets the host part of the URI.
std::string getPathAndQuery() const
Returns the encoded path, query and fragment parts of the URI.
std::unique_ptr< IBaseApi > game_api
void NetSSL_API initializeSSL()
void NetSSL_API uninitializeSSL()
std::function< void(bool, std::string)> callback
static std::string escape(const std::string &s, bool strictJSON=false)