#include <restclient-cpp/connection.h>
#include <restclient-cpp/restclient.h>
#include <sys/time.h>
#include <iostream>
using namespace std;
long long getmstime() {
struct timeval start;
gettimeofday(&start,NULL);
long long tv_sec = start.tv_sec;
long long tv_usec = start.tv_usec;
return tv_sec * 1000 + tv_usec/1000;
}
int main() {
// initialize RestClient
RestClient::init();
// get a connection object
RestClient::Connection* conn = new RestClient::Connection("https://baidu.com");
// set connection timeout to 10ms
conn->SetTimeout(15);
for (int i = 0; i < 10; i++) {
long long start = getmstime();
RestClient::Response r = conn->get("");
cout << getmstime() - start << endl;
cout << r.code << " " << r.body << endl;
}
RestClient::disable();
return 0;
}