gpt4 book ai didi

poco-libraries - 如何在 Poco 中接收 POST 请求内容?

转载 作者:行者123 更新时间:2023-12-01 11:29:32 26 4
gpt4 key购买 nike

我在 Poco 中编写了一个 HTTP 客户端,它将 POST 请求发送到 HTTPServer
以下是片段

Poco::Net::HTTPClientSession s("127.0.0.1", 9090);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/echo");

std::string body("rs=this is a random request body");
request.setContentLength(body.length());
s.sendRequest(request) << body;

服务器收到请求,但以下是我能找到的获取 Steam 的唯一方法(即 rs=this is a ....)
void SRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& hreq, Poco::Net::HTTPServerResponse& resp){
std::istream &i = hreq.stream();
Poco::StreamCopier::copyStream(i, ss, hreq.getContentLength());
}

因此,获取客户端发送的内容的方法是使用字符串。
有没有更简单/直接的方式来获取内容?

最佳答案

你可以试试 Poco/Net/HTMLForm:

Poco::Net::HTMLForm form(hreq, hreq.stream());

那么你可以使用 form.get("rs") 或 form["rs"] 来获取一个带有值的 std::string 。

https://pocoproject.org/docs/Poco.Net.HTMLForm.html

关于poco-libraries - 如何在 Poco 中接收 POST 请求内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33957568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com