-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathHttpRequest.h
More file actions
38 lines (32 loc) · 1.06 KB
/
Copy pathHttpRequest.h
File metadata and controls
38 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Created by mooninwater on 2018/9/19.
//
#ifndef AUTOTRACE_HTTPREQUEST_H
#define AUTOTRACE_HTTPREQUEST_H
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
class HttpRequest{
public:
static void send_request(std::string url,http_request requests,std::function<void(json::value)> callback ) {
http_client client(U(url));
client.request(requests).then([&](http_response response)-> pplx::task<json::value>{
if(response.status_code() == status_codes::OK){
return response.extract_json();
}
return pplx::task_from_result(json::value());
}).then([&](pplx::task<json::value> previousTask){
try{
auto json_data=previousTask.get();
callback(json_data);
}
catch (http_exception const & e){
std::cout << e.what() << std::endl;
}
}).wait();
}
};
#endif //AUTOTRACE_HTTPREQUEST_H