===============================
#include <ESP8266WiFi.h>
const char* host = "api.seniverse.com"; // 网络服务器地址
const int httpPort = 80; // http端口80
WiFiClient wificlient;
String reqRes = "/v3/weather/now.json?key=" + reqUserKey +
+ "&location=" + reqLocation +
"&language=en&unit=" +reqUnit;
/************************
请求方法(GET)+空格+URL+空格+协议(HTTP/1.1)+"\r\n"+
头部字段(Host)+冒号+值(服务器地址)+回车+换行+
头部字段(Connection)+冒号+值(close)+"\r\n"+"\r\n";
************************/
String httpRequest = String("GET ") + reqRes +" HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"\r\n";
wificlient.connect(host, httpPort);
wificlient.print(httpRequest);
while (wificlient.connected() || wificlient.available())
{
if (wificlient.available())
{
String line = wificlient.readStringUntil('\n');
Serial.println(line);
}
}
wificlient.stop();
===============================