Skip to content

Commit c4fb80c

Browse files
committed
update:example
1 parent fa0dd3b commit c4fb80c

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

XEngine_APPClient/APPClient_Download/APPClient_Download.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void P2PParse_List(LPCTSTR lpszMsgBuffer, int nMsgLen, list<P2PFILE_INFO>* pStl_
7979
//创建分布式文件下载器
8080
typedef struct
8181
{
82-
XNETHANDLE xhToken; //下载句柄
82+
XHANDLE xhToken; //下载句柄
8383
__int64x nPosStart;
8484
__int64x nPosEnd;
8585
}P2PFILE_PIECE;
@@ -115,8 +115,8 @@ void P2PFile_Create(list<P2PFILE_INFO>* pStl_ListFile, LPCTSTR lpszFile)
115115
nPos += nPiece;
116116
_stprintf(tszRange, _T("%lld-%lld"), pSt_P2PFile[i].nPosStart, pSt_P2PFile[i].nPosEnd);
117117
}
118-
119-
if (!DownLoad_Http_Create(&pSt_P2PFile[i].xhToken, tszDLUrl, lpszFile, tszRange, NULL, NULL, NULL))
118+
pSt_P2PFile[i].xhToken = DownLoad_Http_Create(tszDLUrl, lpszFile, tszRange, NULL, NULL, NULL);
119+
if (NULL == pSt_P2PFile[i].xhToken)
120120
{
121121
printf("create download task is failed:%X\n", Download_GetLastError());
122122
}
@@ -135,7 +135,7 @@ void P2PFile_Create(list<P2PFILE_INFO>* pStl_ListFile, LPCTSTR lpszFile)
135135
{
136136
bComplete = FALSE;
137137
}
138-
printf("DLToken:%lld DLTotal:%lf DLNow:%lf DLStatus:%d\n", pSt_P2PFile[i].xhToken, st_TaskInfo.dlTotal, st_TaskInfo.dlNow, st_TaskInfo.en_DownStatus);
138+
printf("DLToken:%p DLTotal:%lf DLNow:%lf DLStatus:%d\n", pSt_P2PFile[i].xhToken, st_TaskInfo.dlTotal, st_TaskInfo.dlNow, st_TaskInfo.en_DownStatus);
139139
}
140140
if (bComplete)
141141
{
@@ -160,7 +160,7 @@ int main()
160160
#endif
161161

162162
int nHTTPCode = 0;
163-
int nBodyLen = 2048;
163+
int nBodyLen = 0;
164164
TCHAR *ptszMsgBody = NULL;
165165
//请求分布式存储文件所有位置
166166
LPCTSTR lpszUrl = _T("http://127.0.0.1:5100/Api/Manage/Query");
@@ -169,9 +169,10 @@ int main()
169169
Json::Value st_JsonRoot;
170170
st_JsonRoot["nMode"] = 1; //使用P2P下载
171171
st_JsonRoot["lpszBuckKey"] = "storagekey2";
172-
st_JsonRoot["lpszFileName"] = "qq.exe";
172+
//st_JsonRoot["lpszFileName"] = "qq.exe";
173+
st_JsonRoot["lpszFileHash"] = "D41D8CD98F00B204E9801998ECF8427E";
173174

174-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBody, &nBodyLen))
175+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBody, &nBodyLen))
175176
{
176177
return -1;
177178
}

XEngine_APPClient/APPClient_RestApi/APPClient_RestApi.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void API_Manage_Query()
3838
st_JsonRoot["lpszTimeEnd"];
3939
st_JsonRoot["lpszBuckKey"] = "storagekey2";
4040

41-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
41+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
4242
{
4343
printf("API_Manage_Query:%lX\n", APIHelp_GetLastError());
4444
return;
@@ -66,7 +66,7 @@ void API_Manage_Insert()
6666
st_JsonRoot["List"] = st_JsonArray;
6767
st_JsonRoot["Count"] = 1;
6868

69-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
69+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
7070
{
7171
printf("API_Manage_Insert:%lX\n", APIHelp_GetLastError());
7272
return;
@@ -91,7 +91,7 @@ void API_Manage_Delete()
9191
st_JsonRoot["List"] = st_JsonArray;
9292
st_JsonRoot["Count"] = 1;
9393

94-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
94+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
9595
{
9696
printf("API_Manage_Delete:%lX\n", APIHelp_GetLastError());
9797
return;
@@ -111,7 +111,7 @@ void API_Manage_Dir()
111111
st_JsonRoot["lpszBuckKey"] = "storagekey1";
112112
st_JsonRoot["lpszUserDir"] = "user";
113113
st_JsonRoot["nOPerator"] = 1;
114-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
114+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
115115
{
116116
printf("API_Manage_Dir:%lX\n", APIHelp_GetLastError());
117117
return;
@@ -123,7 +123,7 @@ void API_Manage_Dir()
123123
st_JsonRoot["lpszBuckKey"] = "storagekey1";
124124
st_JsonRoot["lpszUserDir"];
125125
st_JsonRoot["nOPerator"] = 0;
126-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
126+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
127127
{
128128
printf("API_Manage_Dir:%lX\n", APIHelp_GetLastError());
129129
return;
@@ -135,7 +135,7 @@ void API_Manage_Dir()
135135
st_JsonRoot["lpszBuckKey"] = "storagekey1";
136136
st_JsonRoot["lpszUserDir"] = "user";
137137
st_JsonRoot["nOPerator"] = 2;
138-
if (!APIHelp_HttpRequest_Post(lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
138+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
139139
{
140140
printf("API_Manage_Dir:%lX\n", APIHelp_GetLastError());
141141
return;
@@ -150,7 +150,7 @@ void API_Manage_Task()
150150
int nLen = 0;
151151
int nCode = 0;
152152
TCHAR* ptszMsgBuffer = NULL;
153-
if (!APIHelp_HttpRequest_Post(lpszUrl, NULL, &nCode, &ptszMsgBuffer, &nLen))
153+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, NULL, &nCode, &ptszMsgBuffer, &nLen))
154154
{
155155
printf("API_Manage_Task:%lX\n", APIHelp_GetLastError());
156156
return;

XEngine_APPClient/APPClient_UPDownload/APPClient_UPDownload.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using namespace std;
3232
//上传文件
3333
void File_UPLoad()
3434
{
35-
LPCTSTR lpszUrl = _T("http://192.168.1.8:5102/2.txt");
35+
LPCTSTR lpszUrl = _T("http://127.0.0.1:5102/api?filename=newfile4.txt&storeagekey=storagekey2");
3636
int nLen = 0;
3737
int nCode = 0;
3838
TCHAR* ptszMsgBuffer = NULL;
@@ -48,7 +48,7 @@ void File_UPLoad()
4848
OPenSsl_Help_BasicEncoder("123123aa", "123123", tszBaseBuffer);
4949

5050
_stprintf(tszHdrBuffer, _T("Range: bytes=0-5/10\r\nAuthorization: %s\r\n"), tszBaseBuffer);
51-
if (!APIHelp_HttpRequest_Post(lpszUrl, lpszMsgBuffer, &nCode, &ptszMsgBuffer, &nLen, tszHdrBuffer))
51+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, lpszMsgBuffer, &nCode, &ptszMsgBuffer, &nLen, tszHdrBuffer))
5252
{
5353
printf("upload failed:%lX\n", APIHelp_GetLastError());
5454
return;
@@ -66,9 +66,10 @@ void File_UPLoad()
6666
printf("upload:%d\n", nCode);
6767
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
6868
//断点续传必须指定storagekey
69+
nLen = 0;
6970
memset(tszHdrBuffer, '\0', MAX_PATH);
7071
_stprintf(tszHdrBuffer, _T("Range: bytes=5-9/10\r\nAuthorization: %s\r\nStorageKey: %s\r\n"), tszBaseBuffer, tszKeyBuffer);
71-
if (!APIHelp_HttpRequest_Post(lpszUrl, lpszMsgBuffer2, &nCode, &ptszMsgBuffer, &nLen, tszHdrBuffer))
72+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszUrl, lpszMsgBuffer2, &nCode, &ptszMsgBuffer, &nLen, tszHdrBuffer))
7273
{
7374
printf("upload failed:%lX\n", APIHelp_GetLastError());
7475
return;
@@ -79,10 +80,9 @@ void File_UPLoad()
7980
//下载文件
8081
void File_Download()
8182
{
82-
LPCTSTR lpszUrl = _T("http://192.168.1.8:5101/storagekey2/2.txt");
83+
LPCTSTR lpszUrl = _T("http://192.168.1.8:5101/storagekey2/newfile4.txt");
8384

8485
int nLen = 0;
85-
int nCode = 0;
8686
TCHAR* ptszMsgBuffer = NULL;
8787
TCHAR tszBaseBuffer[128];
8888
TCHAR tszHdrBuffer[MAX_PATH];
@@ -92,7 +92,7 @@ void File_Download()
9292
OPenSsl_Help_BasicEncoder("123123aa", "123123", tszBaseBuffer);
9393

9494
_stprintf(tszHdrBuffer, _T("Range: bytes=0-5\r\nAuthorization: %s\r\n"), tszBaseBuffer);
95-
if (!APIHelp_HttpRequest_Get(lpszUrl, &ptszMsgBuffer, &nLen, &nCode, tszHdrBuffer))
95+
if (!APIHelp_HttpRequest_Custom(_T("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nLen, tszHdrBuffer))
9696
{
9797
printf("download failed:%lX\n", APIHelp_GetLastError());
9898
return;
@@ -102,7 +102,7 @@ void File_Download()
102102

103103
memset(tszHdrBuffer, '\0', MAX_PATH);
104104
_stprintf(tszHdrBuffer, _T("Range: bytes=5-10\r\nAuthorization: %s\r\n"), tszBaseBuffer);
105-
if (!APIHelp_HttpRequest_Get(lpszUrl, &ptszMsgBuffer, &nLen, &nCode, tszHdrBuffer))
105+
if (!APIHelp_HttpRequest_Custom(_T("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nLen, tszHdrBuffer))
106106
{
107107
printf("download failed:%lX\n", APIHelp_GetLastError());
108108
return;

0 commit comments

Comments
 (0)