KICAD_CURL_EASY: add SetPostFields().

This commit is contained in:
Alex Shvartzkop 2023-07-29 10:07:01 +05:00
parent 1bc0ceb5a5
commit 712d61d2c1
2 changed files with 30 additions and 0 deletions

View File

@ -230,6 +230,28 @@ bool KICAD_CURL_EASY::SetUserAgent( const std::string& aAgent )
}
bool KICAD_CURL_EASY::SetPostFields(
const std::vector<std::pair<std::string, std::string>>& aFields )
{
std::string postfields;
for( int i = 0; i < aFields.size(); i++ )
{
if( i > 0 )
postfields += "&";
postfields += Escape( aFields[i].first );
postfields += "=";
postfields += Escape( aFields[i].second );
}
if( setOption<const char*>( CURLOPT_COPYPOSTFIELDS, postfields.c_str() ) != CURLE_OK )
return false;
return true;
}
bool KICAD_CURL_EASY::SetURL( const std::string& aURL )
{
if( setOption<const char*>( CURLOPT_URL, aURL.c_str() ) == CURLE_OK )

View File

@ -90,6 +90,14 @@ public:
*/
bool SetUserAgent( const std::string& aAgent );
/**
* Set fields for application/x-www-form-urlencoded POST request.
*
* @param aFields is the vector of fields (key-value pairs).
* @return True if successful, false if not.
*/
bool SetPostFields( const std::vector<std::pair<std::string, std::string>>& aFields );
/**
* Set the request URL.
*