1+ #ifdef _WINDOWS
2+ #include < windows.h>
3+ #include < tchar.h>
4+ #include < json/json.h>
5+ #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
6+ #pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp")
7+ #pragma comment(lib,"Ws2_32")
8+ #else
9+ #ifdef _CENTOS
10+ #include < json/json.h>
11+ #else
12+ #include < jsoncpp/json/json.h>
13+ #endif
14+ #endif
15+ #include < stdio.h>
16+ #include < string.h>
17+ #include < time.h>
18+ #include < list>
19+ #include < XEngine_Include/XEngine_CommHdr.h>
20+ #include < XEngine_Include/XEngine_Types.h>
21+ #include < XEngine_Include/XEngine_ProtocolHdr.h>
22+ #include < XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
23+ #include < XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
24+ #include < XEngine_Include/XEngine_NetHelp/APIHelp_Define.h>
25+ #include < XEngine_Include/XEngine_NetHelp/APIHelp_Error.h>
26+ using namespace std ;
27+
28+ // g++ -std=c++17 -Wall -g APPClient_RestApi.cpp -o APPClient_RestApi.exe -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIHelp -ljsoncpp -Wl,-rpath=../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp,--disable-new-dtags
29+
30+ // 查询
31+ void API_Manage_Query ()
32+ {
33+ LPCTSTR lpszUrl = _T (" http://192.168.1.8:5100/Api/Manage/QueryFile" );
34+ int nLen = 0 ;
35+ int nCode = 0 ;
36+ TCHAR* ptszMsgBuffer = NULL ;
37+ Json::Value st_JsonRoot;
38+ st_JsonRoot[" lpszTimeStart" ];
39+ st_JsonRoot[" lpszTimeEnd" ];
40+ st_JsonRoot[" lpszBuckKey" ] = " storagekey2" ;
41+
42+ if (!APIHelp_HttpRequest_Post (lpszUrl, st_JsonRoot.toStyledString ().c_str (), &nCode, &ptszMsgBuffer, &nLen))
43+ {
44+ printf (" API_Manage_Query:%lX\n " , APIHelp_GetLastError ());
45+ return ;
46+ }
47+ printf (" API_Manage_Query:%d,%s\n " , nCode, ptszMsgBuffer);
48+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
49+ }
50+ // 插入
51+ void API_Manage_Insert ()
52+ {
53+ LPCTSTR lpszUrl = _T (" http://192.168.1.8:5100/Api/Manage/Insert" );
54+ int nLen = 0 ;
55+ int nCode = 0 ;
56+ TCHAR* ptszMsgBuffer = NULL ;
57+ Json::Value st_JsonRoot;
58+ Json::Value st_JsonArray;
59+ Json::Value st_JsonObject;
60+
61+ st_JsonObject[" nFileSize" ] = 10 ;
62+ st_JsonObject[" tszFileHash" ] = " 85E62C9D28FCE775A68DD126E0519F25" ;
63+ st_JsonObject[" tszFileName" ] = " 2.txt" ;
64+ st_JsonObject[" tszBuckKey" ] = " storagekey2" ;
65+ st_JsonArray.append (st_JsonObject);
66+
67+ st_JsonRoot[" List" ] = st_JsonArray;
68+ st_JsonRoot[" Count" ] = 1 ;
69+
70+ if (!APIHelp_HttpRequest_Post (lpszUrl, st_JsonRoot.toStyledString ().c_str (), &nCode, &ptszMsgBuffer, &nLen))
71+ {
72+ printf (" API_Manage_Insert:%lX\n " , APIHelp_GetLastError ());
73+ return ;
74+ }
75+ printf (" API_Manage_Insert:%d,%s\n " , nCode, ptszMsgBuffer);
76+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
77+ }
78+ // 删除
79+ void API_Manage_Delete ()
80+ {
81+ LPCTSTR lpszUrl = _T (" http://192.168.1.8:5100/Api/Manage/Delete" );
82+ int nLen = 0 ;
83+ int nCode = 0 ;
84+ TCHAR* ptszMsgBuffer = NULL ;
85+ Json::Value st_JsonRoot;
86+ Json::Value st_JsonArray;
87+ Json::Value st_JsonObject;
88+
89+ st_JsonObject[" tszFileHash" ] = " 85E62C9D28FCE775A68DD126E0519F25" ;
90+ st_JsonArray.append (st_JsonObject);
91+
92+ st_JsonRoot[" List" ] = st_JsonArray;
93+ st_JsonRoot[" Count" ] = 1 ;
94+
95+ if (!APIHelp_HttpRequest_Post (lpszUrl, st_JsonRoot.toStyledString ().c_str (), &nCode, &ptszMsgBuffer, &nLen))
96+ {
97+ printf (" API_Manage_Delete:%lX\n " , APIHelp_GetLastError ());
98+ return ;
99+ }
100+ printf (" API_Manage_Delete:%d,%s\n " , nCode, ptszMsgBuffer);
101+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
102+ }
103+ // 文件夹
104+ void API_Manage_Dir ()
105+ {
106+ LPCTSTR lpszUrl = _T (" http://192.168.1.8:5100/Api/Manage/Dir" );
107+ int nLen = 0 ;
108+ int nCode = 0 ;
109+ TCHAR* ptszMsgBuffer = NULL ;
110+ Json::Value st_JsonRoot;
111+ // 创建
112+ st_JsonRoot[" lpszBuckKey" ] = " storagekey1" ;
113+ st_JsonRoot[" lpszUserDir" ] = " user" ;
114+ st_JsonRoot[" nOPerator" ] = 1 ;
115+ if (!APIHelp_HttpRequest_Post (lpszUrl, st_JsonRoot.toStyledString ().c_str (), &nCode, &ptszMsgBuffer, &nLen))
116+ {
117+ printf (" API_Manage_Dir:%lX\n " , APIHelp_GetLastError ());
118+ return ;
119+ }
120+ printf (" API_Manage_Dir:%d,%s\n " , nCode, ptszMsgBuffer);
121+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
122+ // 查询
123+ st_JsonRoot.clear ();
124+ st_JsonRoot[" lpszBuckKey" ] = " storagekey1" ;
125+ st_JsonRoot[" lpszUserDir" ];
126+ st_JsonRoot[" nOPerator" ] = 0 ;
127+ if (!APIHelp_HttpRequest_Post (lpszUrl, st_JsonRoot.toStyledString ().c_str (), &nCode, &ptszMsgBuffer, &nLen))
128+ {
129+ printf (" API_Manage_Dir:%lX\n " , APIHelp_GetLastError ());
130+ return ;
131+ }
132+ printf (" API_Manage_Dir:%d,%s\n " , nCode, ptszMsgBuffer);
133+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
134+ // 删除
135+ st_JsonRoot.clear ();
136+ st_JsonRoot[" lpszBuckKey" ] = " storagekey1" ;
137+ st_JsonRoot[" lpszUserDir" ] = " user" ;
138+ st_JsonRoot[" nOPerator" ] = 2 ;
139+ if (!APIHelp_HttpRequest_Post (lpszUrl, st_JsonRoot.toStyledString ().c_str (), &nCode, &ptszMsgBuffer, &nLen))
140+ {
141+ printf (" API_Manage_Dir:%lX\n " , APIHelp_GetLastError ());
142+ return ;
143+ }
144+ printf (" API_Manage_Dir:%d,%s\n " , nCode, ptszMsgBuffer);
145+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
146+ }
147+ // 任务管理
148+ void API_Manage_Task ()
149+ {
150+ LPCTSTR lpszUrl = _T (" http://192.168.1.8:5100/Api/Manage/Task" );
151+ int nLen = 0 ;
152+ int nCode = 0 ;
153+ TCHAR* ptszMsgBuffer = NULL ;
154+ if (!APIHelp_HttpRequest_Post (lpszUrl, NULL , &nCode, &ptszMsgBuffer, &nLen))
155+ {
156+ printf (" API_Manage_Task:%lX\n " , APIHelp_GetLastError ());
157+ return ;
158+ }
159+ printf (" API_Manage_Task:%d,%s\n " , nCode, ptszMsgBuffer);
160+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
161+ }
162+
163+ int main ()
164+ {
165+ #ifdef _WINDOWS
166+ WSADATA st_WSAData;
167+ WSAStartup (MAKEWORD (2 , 2 ), &st_WSAData);
168+ #endif
169+
170+ API_Manage_Query ();
171+ API_Manage_Insert ();
172+ API_Manage_Delete ();
173+ API_Manage_Dir ();
174+ API_Manage_Task ();
175+ #ifdef _WINDOWS
176+ WSACleanup ();
177+ #endif
178+ return 0 ;
179+ }
0 commit comments