Browse Source

#IQRV #comment [Restful] 重构结构体内容2

gifur 3 years ago
parent
commit
b7cc7e9098
1 changed files with 11 additions and 0 deletions
  1. 11 0
      Module/include/CommEntityRestful.hpp

+ 11 - 0
Module/include/CommEntityRestful.hpp

@@ -32,6 +32,17 @@ static bool ExtractDataFromDebranchResponse(const std::string& content, T& outDa
     return (!GetJsonRootObject(rawRoot, content)) ? false : Json2Object(outDataStruct, rawRoot["data"]);
 }
 
+template <typename T>
+static bool FulfillRequestJsonBody(HttpClientRequestConfig* pConfig, const T& dataStruct)
+{
+    std::string jsonValue;
+    if (Object2Json(jsonValue, dataStruct)) {
+        pConfig.SetJsonBody(jsonValue);
+        return true;
+    }
+    return false;
+}
+
 } //Restful
 
 } //Module