-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are there any HTTP(s) client examples? #56
Comments
If you read the README.md you'll notice its still in development. I'm moments away from checking-in the HTTP client example. HTTPS example will follow tomorrow at some point; logic is already present. For now explore the restbed::Http class, Regression, Integration, and Acceptance Tests. |
Thanks, I have been read the http client example source code, but I have a suggestion: It's possible an option allows set the request timeout. |
We'll investigate this proposal shortly. auto settings = make_shared< Settings >( );
settings->set_connection_limit( milliseconds( 30 ) );
Http::sync( const Request& request, const Settings& settings ); |
@pengweichu out of curiosity, we'd love to hear about what your building? |
I use this for the servers communicate, for example, I have some servers, one central server provides the REST API service, another servers use the HTTPS client connect to central server and call the REST API to get/post messages with central server. For a scenario, if a server call a REST API but the central server doesn't respond(for some reason likes query database takes long time), so the HTTPS client request will failed once the timeout, otherwise the request will blocking... In the previous version I use the ZMQ to do that, now I want to replaced it by REST API. Here the code for set the send and receive timeout with asio: class timeout_op
{
public:
timeout_op(unsigned int timeout, int _name)
:timeout_value(timeout),
op_name(_name)
{
}
template<class Protocol>
int level(const Protocol& p) const { return SOL_SOCKET; }
template<class Protocol>
int name(const Protocol& p) const { return op_name; }
template<class Protocol>
const void* data(const Protocol& p) const { return &timeout_value; }
template<class Protocol>
size_t size(const Protocol& p) const { return sizeof(timeout_value); }
private:
unsigned int timeout_value;
int op_name; // SO_SNDTIMEO or SO_RCVTIMEO
};
// For Linux does the time_out need to be /1000 ?
if (send_timeout > 0)
{
timeout_op send_op(send_timeout, SO_SNDTIMEO);
socket->set_option(send_op);
}
if (recv_timeout > 0)
{
timeout_op recv_op(recv_timeout, SO_RCVTIMEO);
socket->set_option(recv_op);
} We can also use the asio::ip::tcp::socket::native to get the native socket to set the SO_SNDTIMEO and SO_RCVTIMEO if don't use above code. |
@ben-crowhurst it's great code, thanks! auto settings = make_shared< Settings >( );
settings->set_connection_limit( milliseconds( 30 ) );
Http::sync( const Request& request, const Settings& settings ); |
Thanks very much, happy new year. |
You're welcome, Happy new year :D |
I'm sorry but I would like to know where has the example for implement a http/https client ?
Thanks.
The text was updated successfully, but these errors were encountered: