{"id":244,"date":"2024-12-08T12:06:31","date_gmt":"2024-12-08T03:06:31","guid":{"rendered":"https:\/\/www.spacek.xyz\/mle\/?p=244"},"modified":"2024-12-08T12:06:31","modified_gmt":"2024-12-08T03:06:31","slug":"cpp-httplib%eb%a5%bc-%ec%82%ac%ec%9a%a9%ed%95%98%ec%97%ac-post-%eb%a1%9c-%ec%84%9c%eb%b2%84%ec%9d%98-%ec%9d%b4%eb%b2%a4%ed%8a%b8%eb%a5%bc-%ec%97%b0%ec%86%8d%ec%9c%bc%eb%a1%9c-%ec%88%98%ec%8b%a0","status":"publish","type":"post","link":"https:\/\/www.spacek.xyz\/mle\/?p=244","title":{"rendered":"cpp-httplib\ub97c \uc0ac\uc6a9\ud558\uc5ec POST \ub85c \uc11c\ubc84\uc758 \uc774\ubca4\ud2b8\ub97c \uc5f0\uc18d\uc73c\ub85c \uc218\uc2e0\ud558\uae30"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">cpp-httplib\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc11c\ubc84 \uc774\ubca4\ud2b8\ub97c \uc218\uc2e0\ud558\ub294 \uacbd\uc6b0 \uc608\uc81c \ubc0f \uad6c\ud604\uc774 GET \ubc29\uc2dd\uc73c\ub85c\ub9cc \ub418\uc5b4 \uc788\ub2e4. \ud558\uc9c0\ub9cc POST \ub97c\uc774\uc6a9\ud558\uc5ec \uc791\uc5c5\ud574\uc57c \ud558\ub294 \uacbd\uc6b0\ub3c4 \uc788\uc73c\ubbc0\ub85c cpp-httplib\ub97c \uc57d\uac04 \uc218\uc815\ud558\uc5ec POST\ub85c \uc774\ubca4\ud2b8\ub97c \uc5f0\uc18d\uc73c\ub85c \uc218\uc2e0\ud558\ub294 \ubc29\ubc95\uc744 \uad6c\ud604\ud574 \ubcf8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uc774\ubca4\ud2b8\ub97c \uc5f0\uc18d\uc73c\ub85c \uc218\uc2e0\ud558\ub294 \uac83\ub294 content receiver \ub97c \uc0ac\uc6a9\ud574\uc57c \ud55c\ub2e4. \uc774\ub97c \uc704\ud574 POST\uc5d0  Client\uc640 ClientImpl \uc5d0 \uc544\ub798\uc640 \uac19\uc774 POST \ud568\uc218\ub97c \ucd94\uac00\ud55c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Client {\n:\n    Result Post(const std::string&amp; path, const Headers&amp; headers, const char* body,\n        size_t content_length, ContentReceiver content_receiver);\n\n\ud568\uc218\uad6c\ud604:\ninline Result Client::Post(const std::string&amp; path, const Headers&amp; headers,\n    const char* body, size_t content_length,\n    ContentReceiver content_receiver) {\n        return cli_->Post(path, headers, body, content_length, content_receiver);\n}\n\nclass ClientImpl {\n:\n    Result Post(const std::string&amp; path, const Headers&amp; headers,\n        const char* body, size_t content_length, ContentReceiver content_receiver);\n\n    Result send_without_content_provider(\n        const std::string&amp; method, const std::string&amp; path,\n        const Headers&amp; headers, const char* body, size_t content_length,\n        ContentReceiver content_receiver,\n        ContentProviderWithoutLength content_provider_without_length,\n        const std::string&amp; content_type, Progress progress);\n\n\n\ud568\uc218\uad6c\ud604\ninline Result ClientImpl::send_without_content_provider(\n    const std::string&amp; method, const std::string&amp; path, const Headers&amp; headers,\n    const char* body, size_t content_length, ContentReceiver content_receiver,\n    ContentProviderWithoutLength content_provider_without_length,\n    const std::string&amp; content_type, Progress progress) {\n    Request req;\n    req.method = method;\n    req.headers = headers;\n    req.path = path;\n    req.content_receiver =\n        &#91;content_receiver](const char* data, size_t data_length,\n            uint64_t \/*offset*\/, uint64_t \/*total_length*\/) {\n                return content_receiver(data, data_length);\n        };\n    req.progress = progress;\n\n    auto error = Error::Success;\n\n    auto res = send_with_content_provider(\n        req, body, content_length, std::move(nullptr),\n        std::move(content_provider_without_length), content_type, error);\n\n    return Result{ std::move(res), error, std::move(req.headers) };\n}\n\ninline Result ClientImpl::Post(const std::string&amp; path, const Headers&amp; headers,\n    const char* body, size_t content_length, ContentReceiver content_receiver) {\n    return send_without_content_provider(\"POST\", path, headers, body, content_length,\n        content_receiver, nullptr, \"application\/x-www-form-urlencoded\", nullptr);\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\uc544\ub798\ub294 \uc704\uc5d0 \uad6c\ud604\ub41c POST \ub97c \uc0ac\uc6a9\ud55c \uc608\uc81c\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httplib::Headers headers = {\n  { \"Hello\", \"World!\" },\n  :\n};\nstd::string\tstrPostData = \"events=....\";\nstd::string\tbody;\nauto res = cli.Post(\"\/rest\/eventSrc.json\", headers, strPostData.c_str(), strPostData.size(), &#91;&amp;](const char* data, size_t data_length) {\n\tbody.append(data, data_length);\n\treturn true;\n\t});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>cpp-httplib\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc11c\ubc84 \uc774\ubca4\ud2b8\ub97c \uc218\uc2e0\ud558\ub294 \uacbd\uc6b0 \uc608\uc81c \ubc0f \uad6c\ud604\uc774 GET \ubc29\uc2dd\uc73c\ub85c\ub9cc \ub418\uc5b4 \uc788\ub2e4. \ud558\uc9c0\ub9cc POST \ub97c\uc774\uc6a9\ud558\uc5ec \uc791\uc5c5\ud574\uc57c \ud558\ub294 \uacbd\uc6b0\ub3c4 \uc788\uc73c\ubbc0\ub85c cpp-httplib\ub97c \uc57d\uac04 \uc218\uc815\ud558\uc5ec POST\ub85c \uc774\ubca4\ud2b8\ub97c \uc5f0\uc18d\uc73c\ub85c \uc218\uc2e0\ud558\ub294 \ubc29\ubc95\uc744 \uad6c\ud604\ud574 \ubcf8\ub2e4. \uc774\ubca4\ud2b8\ub97c \uc5f0\uc18d\uc73c\ub85c \uc218\uc2e0\ud558\ub294 \uac83\ub294 content receiver \ub97c \uc0ac\uc6a9\ud574\uc57c \ud55c\ub2e4. \uc774\ub97c &hellip; <a href=\"https:\/\/www.spacek.xyz\/mle\/?p=244\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,6],"tags":[67,69,68],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-window-program","category-6","tag-cpp-httplib","tag-event","tag-post"],"views":377,"_links":{"self":[{"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":2,"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions\/246"}],"wp:attachment":[{"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spacek.xyz\/mle\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}