Train_RFID_Linux/ai_matrix/Http/Http.h

61 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by matrixai on 2/10/23.
//
#ifndef MATRIX_CONTROL_HTTPUTIL_H
#define MATRIX_CONTROL_HTTPUTIL_H
#include <mutex>
#include <curl/curl.h>
#include <libssh2.h>
#include "json/json.h"
#include "Log.h"
struct HttpRequest
{
// 接口地址
std::string strUrl;
// 请求类型 [POST, GET]
std::string strType;
};
namespace ai_matrix
{
// 请求方式 POST
std::string REQUEST_POST = "POST";
// 请求方式 GET
std::string REQUEST_GET = "GET";
class HttpUtil final
{
public:
HttpUtil();
~HttpUtil();
/**
* Post请求使用Json传递请求参数
* @param requestUrl 请求地址
* @param json 请求参数
* @return 返回Json格式的字符串
*/
std::string postRequestByJson(std::string strRequestUrl, Json::Value &json);
/**
*
* @param user
* @param password
* @param tenantId
* @return
*/
std::string postRequestGetToken(std::string strRequestUrl, std::string strUsername, std::string strPassword, std::string strTenantId, std::string strAuthorization);
private:
CURL *pCurl_ = nullptr;
// 授权码()
std::string token_;
static size_t callBack(void *pBuffer, size_t size, size_t nmemb, std::string &strResp);
};
}
#endif //MATRIX_CONTROL_HTTPUTIL_H