| 24 | namespace utils { |
| 25 | |
| 26 | std::string get_token(utils::BaseHTTPClient *client, std::string username, std::string password) { |
| 27 | if (nullptr == client) { |
| 28 | return ""; |
| 29 | } |
| 30 | std::string token; |
| 31 | |
| 32 | client->setContentType("application/x-www-form-urlencoded"); |
| 33 | |
| 34 | client->set_request_method("POST"); |
| 35 | |
| 36 | std::string payload = "username=" + username + "&" + "password=" + password; |
| 37 | |
| 38 | client->setPostFields(client->escape(payload)); |
| 39 | |
| 40 | client->submit(); |
| 41 | |
| 42 | if (client->submit() && client->getResponseCode() == 200) { |
| 43 | const std::string &response_body = std::string(client->getResponseBody().data(), client->getResponseBody().size()); |
| 44 | if (!response_body.empty()) { |
| 45 | token = "Bearer " + response_body; |
| 46 | } |
| 47 | } |
| 48 | return token; |
| 49 | } |
| 50 | |
| 51 | void parse_url(const std::string *url, std::string *host, int *port, std::string *protocol) { |
| 52 | static std::string http("http://"); |
no test coverage detected