MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Post

Method Post

src/bitcoin-cli.cpp:879–905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

877}
878
879HTTPResponse 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
907bool HTTPClient::SendRequest(std::string_view request)
908{

Callers 1

CallRPCFunction · 0.80

Calls 3

CConnectionFailedClass · 0.85
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected