REST message authentication

Hello,

I am attempting to send a monitored value from an Arduino WiFi Rev 2 to a secure REST server. I have tested that the REST request with both CURL and SOAPUI, both of which work correctly. Here is the functioning CURL statement where I've substituted the Arduino SECRETS for the actual values:

curl "https://<SECRET_SERVER>/api/now/table/incident/9c2490731bcc1010da4bfd9c0a4bcbc2"
--request GET
--header "Accept:application/json"
--user <SECRET_AUTHUSER>:<SECRET_AUTHPW>

Here is the code that I'm using to perform this activity:

#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASSWORD;
int status = WL_IDLE_STATUS;
int port = 443;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, SECRET_SERVER, port);

void setup() {
  Serial.begin(9600);
  
  Serial.print("Attempting to connect to Network named: ");
  Serial.print(ssid);
  while (status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
    delay(1000);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  Serial.println("Connecting...");

  // Connect to HTTP server
  wifi.setTimeout(5000);
  if (!wifi.connect(SECRET_SERVER, 443)) {
    Serial.println("Connection failed");
    return;
  }

  Serial.println("Connected!");
  
  Serial.println("making GET request");
  client.beginRequest();
  client.sendHeader("Accept", "application/json");
  client.sendBasicAuth(SECRET_AUTHUSER, SECRET_AUTHPW);
  client.get("/api/now/table/incident/9c2490731bcc1010da4bfd9c0a4bcbc2");
  client.endRequest();
  
  int statusCode = client.responseStatusCode();
  String response = client.responseBody();

  Serial.print("GET Status code: ");
  Serial.println(statusCode);
  Serial.print("GET Response: ");
  Serial.println(response);

  wifi.stop();
}

void loop() {
  // not used in this example
}

When I run this code I get the following responses:

Attempting to connect to Network named: <SECRET_SSID>.
SSID: <SECRET_SSID>
IP Address: XXX.XXX.X.XX
Connecting...
Connected!
making GET request
GET Status code: -3
GET Response:

Any suggestions would be greatly appreciated. Thank you in advance!

Bob

you need to use "wifi.connectSSL(SECRET_SERVER, 443)" instead of "wifi.connect(SECRET_SERVER, 443)"

IoT_hobbyist - Thank you very much for your reply. I did change the statement to use wifi.connectSSL, I think that gets me a step closer, unfortunately it has not resolved my issue.

Is there any way to validate what is coming out of the Arduino in terms of the REST statement?

Thank you,

Bob

try to look up in the library what does "GET Status code: -3" mean

Can't thank you enough for helping me, greatly appreciated!

I went to the Arduino HTTPClient code and it turns out that the -3 is a Arduino response that indicates "HTTPC_ERROR_SEND_PAYLOAD_FAILED". In going through the code there may be another way to solve this problem, so I will respond once I've made the changes that "should" work :wink:

Thank you again,

Bob

You're welcome. Good luck!