Simple GET request to ipify is returning a status -2 response

I'm using an Arduino Uno Wifi Rev2 and ArduinoHttpClient.
What I'm attempting to do is send a simple GET request to ipify to get the arduino public IP address.

I'm a complete novice when it comes to this stuff so I'm hopefully doing something obviously wrong.
I'd really appreciate it someone could help me get my request to ipify working properly.

#include "arduino_secrets.h"
#include <ArduinoHttpClient.h>
//#include <WiFi101.h>    // use this for MKR1000
#include <WiFiNINA.h>     // use this for MKR1010 or Nano 33 IoT

//#include <Arduino_JSON.h>
// server address:
const char serverAddress[] = "http://api.ipify.org";
int port = 80;

WiFiSSLClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);

// request timestamp in ms:
long lastRequest = 0;
// interval between requests:
int interval = 10000;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  while ( WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(SECRET_SSID);     // print the network name (SSID);

    // Connect to WPA/WPA2 network:
    WiFi.begin(SECRET_SSID, SECRET_PASS);
  }

  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
}

void loop() {
  if (millis() - lastRequest > interval ) {
    // assemble the path for the GET message:
    String path = "/";

    // send the GET request
    Serial.println("making GET request");
    client.get(path);

    // read the status code and body of the response
    int statusCode = client.responseStatusCode();
    String response = client.responseBody();
    Serial.print("Status code: ");
    Serial.println(statusCode); // status code is -2
    Serial.print("Response: ");
    Serial.println(response);
    lastRequest = millis();
  }
}
const char serverAddress[] = "api.ipify.org";

Thanks for the reply.
I made the change you suggested.
Instead of the status -2 response I now get a 404 status response instead

Actually if I change HttpSSLClient to HttpClient I get the proper response.
Thankyou

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.