基于libhv的https-post

#include <iostream>
#include <string>
#include <hv/requests.h>
using namespace hv;

int main() {

    hv::Json jroot;
    hv::Json d;
    jroot["cmd"] = "req_get_info_iot_base_bu_mid";
    d["mid"] = 9947;
    jroot["data"] = d;
    http_headers headers;
    headers["Content-Type"] = "application/json";

    std::string j = jroot.dump();
    auto resp = requests::post("https://saas.0.cn/v1/fn_saas_core/req_rpc_cmd",j, headers);

    if (resp == NULL) {
        printf("request failed!\n");
    }
    else {
        printf("%d %s\r\n", resp->status_code, resp->status_message());
        printf("%s\n", resp->body.c_str());
    }

    return 0;
}

  

posted @ 2023-06-26 16:32  ahuo  阅读(58)  评论(0编辑  收藏  举报