之前看网上一堆的资料说Microsoft/cpprestsdk不支持https或者说只支持window下的https,差点就被误导了,没办法,只好自己去翻了下源代码
先说明下linux版本把,centos7
创建ssl证书啥的,网上一堆的资料,这边就不再说了,直接贴源代码了
#include <stdio.h>
#include <cpprest/uri.h>
#include <cpprest/http_listener.h>
#include <cpprest/http_client.h>
#include <cpprest/asyncrt_utils.h>
#include <cpprest/filestream.h>
#pragma comment(lib, "cpprest_2_7.lib")
#pragma comment(lib, "bcrypt.lib")
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "winhttp.lib")
#pragma comment(lib, "httpapi.lib")
using namespace web;
using namespace http;
using namespace utility;
using namespace http::experimental::listener;
using namespace web::http;
using namespace web::http::client;
//using namespace concurrency;
class CommandHandler
{
public:
CommandHandler() {
}
CommandHandler(utility::string_t url,http_listener_config server_config);
pplx::task<void> open() {
return m_listener.open(); }
pplx::task<void> close() {
return m_listener.close(); }
private:
void handle_get(http_request message);
void handle_post(http_request message);
void handle_put(http_request message);
void handle_del(http_request message);
http_listener m_listener;
};
CommandHandler::CommandHandler(utility::string_t url,http_listener_config server_config) : m_listener(url,server_config)
{
m_listener.support(methods::GET, std::bind(&CommandHandler::handle_get, this, std::placeholders::_1));
m_listener.support