-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebClient2.ino
52 lines (41 loc) · 1007 Bytes
/
WebClient2.ino
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
52
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
void setup()
{
Serial.begin(9600);
WiFi.mode(WIFI_STA);//设为无线终端模式
WiFi.begin("laptop111","87654321");
while(WiFi.status()!=WL_CONNECTED)
{
delay(1000);
Serial.println("尝试连接。。。");
}
Serial.println("连接完成!");
httpClientStart();
}
void loop()
{
}
void httpClientStart()
{
WiFiClient client;
String httpRequests="GET / HTTP/1.1\r\n Host: www.bilibili.com\r\nConnection: close\r\n\r\n ";
if(client.connect("www.bilibili.com",80))
{
Serial.println("访问成功!");
client.print(httpRequests);
while(client.connected()||client.available())
{
if(client.available())
{
String line=client.readStringUntil('\n');
Serial.print(line);
}
}
client.stop();
}
else
{
Serial.println("连接失败!");
}
}