-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
46 lines (35 loc) · 1004 Bytes
/
test.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
#include <stdio.h>
#include "YDNSResolver.h"
#include "ssl/YMbedtls.h"
#include "YTCPClient.h"
#include "YAddress.h"
#include "poll/SelectPoll.h"
#include "http/YHttpRequest.h"
int main() {
YHttpRequest request;
request.request("GET", "https://www.baidu.com");
SelectPoll selectPoll;
request.setIOPoll((IOPoll*)&selectPoll);
request.onRead([](YHttpRequest*, YHttpRespond*, const char* buff, int dataLen) {
auto f = fopen("test.html", "a+");
fwrite((void*)buff, 1, dataLen, f);
fclose(f);
});
//request.perform();
/*YTCPClient tcpClient;
YAddress address(std::string("14.215.177.39"), 443);
tcpClient.setSSLFlag(true);
tcpClient.connect(&address);
const char* data = "GET / HTTP/1.1\r\n\r\n";
int sendLen = tcpClient.send(data, strlen(data));
char buff[1024] = {0x00};
tcpClient.receive(buff, 1024);*/
YDNSResolver resolver;
std::vector<std::string> ret;
resolver.lookupByName(std::string("www.baidu.com"), ret);
while (1)
{
selectPoll.wait(1000);
}
return 0;
}