【发布时间】:2018-10-29 02:44:37
【问题描述】:
我正在使用 NodeMCU 来使用 ESP8266,我想使用 ipify 来获取公共 IP 地址。
但我在httpCode 上得到-1。这是为什么呢?
如果我输入api.ipify.org,它会正确获取我的公共 IP 地址。
void loop() {
Serial.println(WiFi.status());
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
Serial.println("az");
HTTPClient http; //Declare an object of class HTTPClient
http.begin("https://api.ipify.org/?format=json"); //Specify request destination
int httpCode = http.GET(); //Send the request
Serial.println(httpCode); //<<---- Here I get -1
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
delay(10000); //Send a request every 30 seconds
}
【问题讨论】:
标签: arduino ip-address esp8266 arduino-esp8266