【问题标题】:Multiple http response poco.多个 http 响应 poco。
【发布时间】:2014-05-14 05:29:58
【问题描述】:

您好,我想发送一个 HTTP 请求并收到多个响应,但我不知道该怎么做。我使用标准函数。

我有这样的:

        HTTPSClientSession session("localhost", 9090);
    session.setKeepAlive(true);

    HTTPRequest req(HTTPRequest::HTTP_POST, "/",    HTTPMessage::HTTP_1_1);
    req.setContentType("multipart/form-data");
    session.sendRequest(req);

    // get response
    HTTPResponse res;
    cout << res.getStatus() << " " << res.getReason() << endl;

    // print response
    istream &is = session.receiveResponse(res);
    StreamCopier::copyStream(is, cout);
    cout << "" << endl;

    //get annother response
    HTTPResponse res2;
    istream &is2 = session.receiveResponse(res2);
    StreamCopier::copyStream(is2, cout);
    cout << "" << endl;

服务器部分如下:

virtual void handleRequest(HTTPServerRequest &request, HTTPServerResponse &response) {  
            response.setStatus(HTTPResponse::HTTP_OK);
        response.setContentType("text/html");


        ostream& out = response.send();
        out << "WAIT FOR RESULT" <<endl;
        out.flush();


        response.setStatus(HTTPResponse::HTTP_OK);
        response.setContentType("text/html");
        response.send();
        ostream &o = response.send();
        o << "RESULT" << endl;
        o.flush();
}

感谢您的回答。

【问题讨论】:

    标签: sql-server http client httpresponse poco


    【解决方案1】:

    基本的 HTTP 不支持这种功能,也许你应该在 HTTP 中创建自己的协议,比如你想要两个答案,在响应中返回一个支持多个答案的正文, 例如:

    [
      {
        response{status:200, accept:application/json, body:{...}}
      },
      {
        response{status:404, accept:application/json, body:{...}}
      }
    ]
    

    就我而言,您正在寻找的是一个 websocket,您应该研究 WS 协议以建立一个并能够实时发送和接收信息,或者您可以使用另一种技术,如 NodeJS这超级简单。

    treehouse team's blog 上有关 websocket 的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 2015-05-05
      • 2018-04-14
      相关资源
      最近更新 更多