|
@@ -32,6 +32,9 @@
|
|
|
* -2:超时
|
|
|
* -3:地址不符合规范
|
|
|
*/
|
|
|
+
|
|
|
+typedef void (*restFul_GetTokenCallBack)(char *, char *);
|
|
|
+
|
|
|
RESTFULFUNC_API int HttpProbe(const std::string& url, std::string& out_msg, uint32_t wait_max_secs = (uint32_t)-1);
|
|
|
|
|
|
/*!
|
|
@@ -118,20 +121,23 @@ struct HttpClientRequestConfig
|
|
|
* @param[out]
|
|
|
* @return :
|
|
|
*/
|
|
|
- HttpClientRequestConfig(const std::string& uri)
|
|
|
+ HttpClientRequestConfig(const std::string& uri, restFul_GetTokenCallBack t_getToken)
|
|
|
:mMethod(HttpRequestMethod::GET), mUri(uri), mToValidCert(false)
|
|
|
- , mBodyContent(""), mContentType(""), mHeaderAcceptType("application/json"), mTimeoutSecs(0)
|
|
|
+ , mBodyContent(""), mContentType(""), mHeaderAcceptType("application/json"), mTimeoutSecs(0), m_withToken(true)
|
|
|
{
|
|
|
+ InitGetToken(t_getToken);
|
|
|
}
|
|
|
- HttpClientRequestConfig(HttpRequestMethod method)
|
|
|
- : mMethod(method), mToValidCert(false), mBodyContent(""), mHeaderAcceptType("application/json")
|
|
|
+ HttpClientRequestConfig(HttpRequestMethod method, restFul_GetTokenCallBack t_getToken)
|
|
|
+ : mMethod(method), mToValidCert(false), mBodyContent(""), mHeaderAcceptType("application/json"), m_withToken(true)
|
|
|
, mContentType(""), mTimeoutSecs(0)
|
|
|
{
|
|
|
+ InitGetToken(t_getToken);
|
|
|
}
|
|
|
- HttpClientRequestConfig(HttpRequestMethod method, const std::string& uri)
|
|
|
- :mMethod(method), mUri(uri), mToValidCert(false), mBodyContent("")
|
|
|
+ HttpClientRequestConfig(HttpRequestMethod method, const std::string& uri, restFul_GetTokenCallBack t_getToken)
|
|
|
+ :mMethod(method), mUri(uri), mToValidCert(false), mBodyContent(""), m_withToken(true)
|
|
|
, mContentType(""), mHeaderAcceptType("application/json"), mTimeoutSecs(0)
|
|
|
{
|
|
|
+ InitGetToken(t_getToken);
|
|
|
}
|
|
|
|
|
|
void SetRequestType(HttpRequestMethod method) { mMethod = method; }
|
|
@@ -175,6 +181,22 @@ struct HttpClientRequestConfig
|
|
|
virtual void PreDo() {}
|
|
|
virtual void PostDo() {}
|
|
|
|
|
|
+ bool getToken(std::string & t_channelId, std::string &t_token) const {
|
|
|
+ char channelId[256] = "";
|
|
|
+ char token[256] = "";
|
|
|
+ if (m_withToken && g_tokenCall != NULL)
|
|
|
+ {
|
|
|
+ g_tokenCall(channelId, token);
|
|
|
+ if (std::string(channelId).length() > 0 && std::string(token).length() > 0)
|
|
|
+ {
|
|
|
+ t_channelId = channelId;
|
|
|
+ t_token = token;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
|
|
|
HttpRequestMethod mMethod;
|
|
@@ -186,20 +208,30 @@ private:
|
|
|
|
|
|
std::map<std::string, std::string> mQueryPairs;
|
|
|
|
|
|
+ bool m_withToken;
|
|
|
bool mToValidCert;
|
|
|
uint32_t mTimeoutSecs;
|
|
|
+ restFul_GetTokenCallBack g_tokenCall;
|
|
|
+ void InitGetToken(restFul_GetTokenCallBack t_getToken) {
|
|
|
+ if (t_getToken)
|
|
|
+ g_tokenCall = t_getToken;
|
|
|
+ else
|
|
|
+ g_tokenCall = nullptr;
|
|
|
+
|
|
|
+
|
|
|
+ };
|
|
|
};
|
|
|
|
|
|
struct HttpClientPostTypeRequest : public HttpClientRequestConfig
|
|
|
{
|
|
|
HttpClientPostTypeRequest(const std::string& uri)
|
|
|
- :HttpClientRequestConfig(HttpRequestMethod::POST, uri) {}
|
|
|
+ :HttpClientRequestConfig(HttpRequestMethod::POST, uri, nullptr) {}
|
|
|
};
|
|
|
|
|
|
struct HttpClientUploadRequest : public HttpClientRequestConfig
|
|
|
{
|
|
|
HttpClientUploadRequest(const std::string& uri)
|
|
|
- :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri)
|
|
|
+ :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri, nullptr)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -236,7 +268,7 @@ private:
|
|
|
struct HttpClientDownloadRequest : public HttpClientRequestConfig
|
|
|
{
|
|
|
HttpClientDownloadRequest(const std::string& uri)
|
|
|
- :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri) {
|
|
|
+ :HttpClientRequestConfig(HttpRequestMethod::DOWNLOAD, uri, nullptr) {
|
|
|
SetAcceptType("*/*");
|
|
|
}
|
|
|
};
|