-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (39 loc) · 1.07 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include <stdio.h>
#include "MgHttpClient.h"
bool writeJsonToFile(const char* szBuffer, int nlen, const char* szFileName)
{
if ( NULL == szBuffer || nlen <= 0 || NULL == szFileName )
{
return true;
}
FILE* fpJson = fopen(szFileName, "wb");
if (NULL == fpJson)
{
printf("fopen failed %s\n", szFileName);
return false;
}
fwrite( szBuffer, 1, nlen, fpJson );
fclose( fpJson );
return true;
}
int main(int argc, char** argv)
{
const char* szJsonUrl = "http://www.hkex.com.hk/chi/csm/shortsell/data_tab_short_selling_20181218c.js";
const char* szSaveResFileName = "20181218c.js";
const char* szSaveResFileName2 = "20181219c.js";
{
//block model;
MgHttpClient httpClient;
httpClient.sendReq(szJsonUrl, writeJsonToFile, szSaveResFileName, NULL, NULL, false);
int i = 0;
++i;
}
//nonblock model(nonHttpClient 这个对象必须在callback函数执行完才能释放,或者一直存在);
MgHttpClient nonHttpClient;
nonHttpClient.sendReq(szJsonUrl, writeJsonToFile, szSaveResFileName2, NULL, NULL, true);
int i = 0;
++i;
system("pause");
return 0;
}