Using POST an WIFININA with SSL on Uno Wifi Rev 2

Hello,

I’m using an Uno Wifi Rev2 and want to post some data into a MySQL Database. The connection to the server works fine, but the body of the response saying: “Table doesn’t have a default value”. I think, the GET method can’t read the value, but a browser-test worked (…/writeData.php?value1=1).

My code:

#include <WiFiNINA.h>

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



char ssid[] = "****";
char pass[] = "****";


int test = 1;

const char serverName[] = "****";
int port = 443;
WiFiSSLClient wifi;
HttpClient client = HttpClient(wifi, serverName, port);

int status = WL_IDLE_STATUS;


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

}

void loop() {
  
    String httpRequestData = "value1=" + test;
    Serial.println("making POST request");
    String contentType = "application/x-www-form-urlencoded";
    String postData = httpRequestData;

    client.post("/tp/writeData.php?", contentType, postData);
    int statusCode = client.responseStatusCode();
    Serial.print("Status code: ");
    Serial.println(statusCode);
    String response = client.responseBody();
    Serial.print("Response: ");
    Serial.println(response);

    Serial.println("Wait 10 seconds");
    delay(10000);
  
}

Thanks for helping!

I think, the GET method can’t read the value, but a browser-test worked (…/writeData.php?value1=1).

Exactly because in your code you do a POST request and not a GET request. I don’t know the server side but if that expects a GET request your code is wrong.

Ok, I will try it! Thanks a lot!

pylon:
Exactly because in your code you do a POST request and not a GET request. I don't know the server side but if that expects a GET request your code is wrong.

Ok, that's the answer! I've used the wrong PHP-method at the server.
Thank you very much!