Http GET Second Request always fails

Working on a Uno with a shield and writing back to a Asp.net API and I'm running into a weird issue that I can't figure out. Either of the request below will run when I call it the first time but any subsequent runs of the same method or different will fail with http 400 invalid url. I can spam both API calls through postman without issue so it's something to do with how I'm handling the client and for the life of me I can't figure it out. I changed the connection test portion on the Limits call just to verify I was actually disconnecting and based on serial output everything looks good.

Loaded libraries are
#include <Adafruit_ADS1X15.h>
#include <SPI.h>
#include <Ethernet.h>
#include <AsyncDelay.h>
#include <ArduinoJson.h> //Not yet in use

void GetArduinoLimits() {

  String PostData = "ArduinoID=" + String(ArduinoID);
  // Serial.println("Inside Limit Check");
  if(!client.connected()){
    Serial.println("Not Connected");
      client.connect(server, 80);
  }

  if(client.connected()){
    Serial.println("Connected");
    client.println("GET /NIC-API-Dev/api/EWI/ArduinoLimit?ArduinoID=" + String(ArduinoID) + " HTTP/1.1");
    client.println("Host: XX.XX.XX.XX");
    client.println("Connection: close");
    client.println("Content-Length: 0");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
}

  while (client.connected() && !client.available()) delay(1);

  while (client.connected() || client.available()) {
    char c = client.read();                           //gets byte from ethernet buffer
    readString += c;
    Serial.print(c);
  }

   if (!client.connected()) {
       client.stop();
   }
}

void GetArduinoIsSetup() {
  String PostData = "ArduinoID=" + String(ArduinoID) + "?isSetupRun=1";
  if (client.connect(server, 80)) {
    Serial.println("isSetup Connected");
    client.println("GET /NIC-API-Dev/api/EWI/ArduinoIsSetup?ArduinoID=" + String(ArduinoID) + "&isSetupRun=1" + " HTTP/1.1");
    client.println("Host: XX.XX.XX.XX");
    client.println("Connection: close");
    client.println("Content-Length: 0");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
  }

  while (client.connected() && !client.available()) delay(1);
  while (client.connected() || client.available()) {
    char c = client.read();                         
    readString += c;
    Serial.print(c);
  }

  if (!client.connected()) {
    client.stop();
        Serial.println("---------End of Response Header---------");
    Serial.println(readString.substring(readString.indexOf('{')));
    readString = "";
    // readString = readString.substring(readString.indexOf('{'));
    // deserializeJson(jdoc,readString);
    // const char* tst = jdoc["result"];
    // Serial.println(tst);
  }
}


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