MKR1000 GET request

Hello, I’m trying to make a GET request with MKR1000 board using the SimpleGet example:

#include <ArduinoHttpClient.h>
#include <WiFi101.h>
#include <SPI.h>

#include "arduino_secrets.h"

/////// Wifi Settings ///////
char ssid[] = SECRET_SSID;
//char pass[] = SECRET_PASS;


char serverAddress[] = "http://jsonplaceholder.typicode.com";  // server address
int port = 80;

WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;

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

    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid);
  }

  // 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() {
  Serial.println("making GET request");
  client.get("/posts");

 

  // read the status code and body of the response
  statusCode = client.responseStatusCode();
  response = client.responseBody();

  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.print("Response: ");
  Serial.println(response);
  Serial.println("Wait five seconds");
  delay(5000);
}

And I get the following message:

SSID: mywifi
IP Address: myIP
making GET request
Status code: -2
Response:
Wait five seconds

I also tried with just “jsonplaceholder.typicode.com” in the address and I get a -3 status code. I have tried some other examples but I’m unable to make an http, post or get request. Do you have some advice?

Thank you for your help.

This example may help you

Notice the use of the CLIENT commands.

A slightly different example here using server status

If you read the whole page you will see that GET and PUT are not used directly.