From 1ad4ef50531af1ed937039f8d8312b62346fd4be Mon Sep 17 00:00:00 2001 From: zvon Date: Tue, 25 Feb 2020 10:20:45 +0100 Subject: [PATCH] Windows/network: support status code --- windows/network.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/windows/network.cpp b/windows/network.cpp index 0c1bc41..5b579e0 100644 --- a/windows/network.cpp +++ b/windows/network.cpp @@ -20,7 +20,7 @@ Request::~Request() { } std::string sendRequest( HINTERNET hRequest, const std::wstring &headers, - const std::string &optional ) { + const std::string &optional, int &status_code ) { std::string response{}; response.reserve( 10000 ); @@ -64,7 +64,7 @@ std::string Request::get( const std::wstring &url ) { if ( !hRequest ) std::wcerr << "ERROR HttpOpenRequest: " << GetLastError() << std::endl; - return sendRequest( hRequest, _headers, "" ); + return sendRequest( hRequest, _headers, "", status_code ); } std::string Request::post( const std::wstring &url, const std::string &data ) { @@ -74,7 +74,7 @@ std::string Request::post( const std::wstring &url, const std::string &data ) { if ( !hRequest ) std::wcerr << "ERROR HttpOpenRequest: " << GetLastError() << std::endl; - return sendRequest( hRequest, _headers, data ); + return sendRequest( hRequest, _headers, data, status_code ); } void Request::addHeader( const std::wstring &header ) { @@ -99,7 +99,11 @@ void Request::setServer( const string &server ) { } int Request::lastResponseCode() { +#ifndef _WIN32 long code{}; curl_easy_getinfo( _curl_handle, CURLINFO_RESPONSE_CODE, &code ); return code; +#else + return status_code; +#endif }