| 877 | } |
| 878 | |
| 879 | HTTPResponse HTTPClient::Post(const std::string& endpoint, |
| 880 | std::span<const std::pair<std::string, std::string>> headers, |
| 881 | const std::string& body) |
| 882 | { |
| 883 | try { |
| 884 | // Build HTTP request |
| 885 | std::string request = strprintf("POST %s HTTP/1.1\r\n" |
| 886 | "Host: %s\r\n" |
| 887 | "Connection: close\r\n" |
| 888 | "Content-Length: %d\r\n", |
| 889 | endpoint, m_host, body.size()); |
| 890 | |
| 891 | for (const auto& [name, value] : headers) { |
| 892 | request += strprintf("%s: %s\r\n", name, value); |
| 893 | } |
| 894 | request += "\r\n"; |
| 895 | request += body; |
| 896 | |
| 897 | if (!SendRequest(request)) { |
| 898 | throw CConnectionFailed("Failed to send HTTP request"); |
| 899 | } |
| 900 | |
| 901 | return ReadResponse(); |
| 902 | } catch (const HTTPError& e) { |
| 903 | throw CConnectionFailed(strprintf("HTTP error: %s", e.what())); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | bool HTTPClient::SendRequest(std::string_view request) |
| 908 | { |
no test coverage detected