Function newHttpClient

Summary

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

(1) static HttpClientPtr newHttpClient(const std::string &ip, uint16_t port, bool useSSL=false, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)

(2) static HttpClientPtr newHttpClient(const std::string &hostString, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)

Function overload

Synopsis

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

static HttpClientPtr newHttpClient(const std::string &ip, uint16_t port, bool useSSL=false, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)

Description

Creaet a new HTTP client which use ip and port to connect to server.

Parameters

ip - The ip address of the HTTP server

port - The port of the HTTP server

useSSL - if the parameter is set to true, the client connects to the server using HTTPS.

loop - If the loop parameter is set to nullptr, the client uses the HttpAppFramework's event loop, otherwise it runs in the loop identified by the parameter.

useOldTLS - If the parameter is set to true, the TLS1.0/1.1 are eanbled for HTTPS.

validateCert - If the parameter is set to true, the client validates the server certificate when SSL handshaking.

Returns
HttpClientPtr The smart pointer to the new client object.
Note
: The ip parameter support for both ipv4 and ipv6 address

Mentioned in

Source

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

Synopsis

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

static HttpClientPtr newHttpClient(const std::string &hostString, trantor::EventLoop *loop=nullptr, bool useOldTLS=false, bool validateCert=true)

Description

Create a Http client using the hostString to connect to server.

Parameters

hostString - this parameter must be prefixed by 'http://' or 'https://'.

Examples for hostString:
https://www.baidu.com
http://www.baidu.com
https://127.0.0.1:8080/
http://127.0.0.1
http://[::1]:8080/   //IPv6 address must be enclosed in [], rfc2732
Parameters

loop - If the loop parameter is set to nullptr, the client uses the HttpAppFramework's event loop, otherwise it runs in the loop identified by the parameter.

useOldTLS - If the parameter is set to true, the TLS1.0/1.1 are enabled for HTTPS.

Note
Parameters

validateCert - If the parameter is set to true, the client validates the server certificate when SSL handshaking.

Note
Don't add path and parameters in hostString, the request path and parameters should be set in HttpRequestPtr when calling the sendRequest() method.

Mentioned in

Source

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






Add Discussion as Guest

Log in