Function sendRequest

Summary

#include <lib/inc/drogon/HttpClient.h>

(1) virtual void sendRequest(const HttpRequestPtr &req, const HttpReqCallback &callback, double timeout=0)=0

(2) virtual void sendRequest(const HttpRequestPtr &req, HttpReqCallback &&callback, double timeout=0)=0

(3) std::pair< ReqResult, HttpResponsePtr > sendRequest(const HttpRequestPtr &req, double timeout=0)

Function overload

Synopsis

#include <lib/inc/drogon/HttpClient.h>

virtual void sendRequest(const HttpRequestPtr &req, const HttpReqCallback &callback, double timeout=0)=0

Description

Send a request asynchronously to the server.

Parameters:

req - The request sent to the server.

callback - The callback is called when the response is received from the server.

timeout - In seconds. If the response is not received within the timeout, the callback is called with ReqResult::Timeout and an empty response. The zero value by default disables the timeout.

Note
The request object is altered(some headers are added to it) before it is sent, so calling this method with a same request object in different thread is dangerous. Please be careful when using timeout on an non-idempotent request.

Source

Line 65 in lib/inc/drogon/HttpClient.h.

Synopsis

#include <lib/inc/drogon/HttpClient.h>

virtual void sendRequest(const HttpRequestPtr &req, HttpReqCallback &&callback, double timeout=0)=0

Description

Send a request asynchronously to the server.

Parameters:

req - The request sent to the server.

callback - The callback is called when the response is received from the server.

timeout - In seconds. If the response is not received within the timeout, the callback is called with ReqResult::Timeout and an empty response. The zero value by default disables the timeout.

Note
The request object is altered(some headers are added to it) before it is sent, so calling this method with a same request object in different thread is dangerous. Please be careful when using timeout on an non-idempotent request.

Source

Line 85 in lib/inc/drogon/HttpClient.h.

Synopsis

#include <lib/inc/drogon/HttpClient.h>

std::pair< ReqResult, HttpResponsePtr > sendRequest(const HttpRequestPtr &req, double timeout=0)

Description

Send a request synchronously to the server and return the response.

Parameters:

req -

timeout - In seconds. If the response is not received within the timeout, the ReqResult::Timeout and an empty response is returned. The zero value by default disables the timeout.

Return
std::pair<ReqResult, HttpResponsePtr>
Note
Never call this function in the event loop thread of the client (partially in the callback function of the asynchronous sendRequest method), otherwise the thread will be blocked forever. Please be careful when using timeout on an non-idempotent request.

Source

Lines 104-116 in lib/inc/drogon/HttpClient.h.

std::pair<ReqResult, HttpResponsePtr> sendRequest(const HttpRequestPtr &req,
                                                  double timeout = 0)
{
    std::promise<std::pair<ReqResult, HttpResponsePtr>> prom;
    auto f = prom.get_future();
    sendRequest(
        req,
        [&prom](ReqResult r, const HttpResponsePtr &resp) {
            prom.set_value({r, resp});
        },
        timeout);
    return f.get();
}





Add Discussion as Guest

Log in to DocsForge