Windows/network: support status code

This commit is contained in:
zvon 2020-02-25 10:20:45 +01:00
parent e6b2aeecad
commit 1ad4ef5053

View File

@ -20,7 +20,7 @@ Request::~Request() {
} }
std::string sendRequest( HINTERNET hRequest, const std::wstring &headers, std::string sendRequest( HINTERNET hRequest, const std::wstring &headers,
const std::string &optional ) { const std::string &optional, int &status_code ) {
std::string response{}; std::string response{};
response.reserve( 10000 ); response.reserve( 10000 );
@ -64,7 +64,7 @@ std::string Request::get( const std::wstring &url ) {
if ( !hRequest ) if ( !hRequest )
std::wcerr << "ERROR HttpOpenRequest: " << GetLastError() << std::endl; 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 ) { 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 ) if ( !hRequest )
std::wcerr << "ERROR HttpOpenRequest: " << GetLastError() << std::endl; 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 ) { void Request::addHeader( const std::wstring &header ) {
@ -99,7 +99,11 @@ void Request::setServer( const string &server ) {
} }
int Request::lastResponseCode() { int Request::lastResponseCode() {
#ifndef _WIN32
long code{}; long code{};
curl_easy_getinfo( _curl_handle, CURLINFO_RESPONSE_CODE, &code ); curl_easy_getinfo( _curl_handle, CURLINFO_RESPONSE_CODE, &code );
return code; return code;
#else
return status_code;
#endif
} }