Getting response code (200) from server for POST (MKRNB.h)

I'm using sketch below to upload data to server with MKR NB1500 and it works ok. How can I get/read response code from server to see if upload was succesfull?

The sketch has this but it doesn't read any response:

if (client.available()) {
Serial.print((char)client.read());
}

// libraries
#include <MKRNB.h>

#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = SECRET_PINNUMBER;

// initialize the library instance
NBClient client;
GPRS gprs;
NB nbAccess(true);

char SerialNum[] = "mds00000";
float gaugeMeasurement = 1.23;
char dataInJSON[500];



void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  boolean connected = false;

  // After starting the modem with NB.begin()
  // attach to the GPRS network with the APN, login and password
  while (!connected) {
    if ((nbAccess.begin(PINNUMBER) == NB_READY) &&
        (gprs.attachGPRS() == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  sprintf(dataInJSON, "{\"serNum\": \"%s\",\"mitu1\": \"%.2f\"}", SerialNum, gaugeMeasurement);
  Serial.println(strlen(dataInJSON)); 
}

void loop() {
  Serial.println("connecting...");
  
  if (client.connect("www.xxx.xx",80)) {
    client.println("POST /yyy/index.php HTTP/1.1"); 
    client.println("Host: www.xxx.xx");
    client.println("Content-Type: application/x-www-form-urlencoded"); 
    client.print("Content-Length: "); 
    client.println(strlen(dataInJSON)); 
    client.println(); 
    client.print(dataInJSON); 
  } 

  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    Serial.print((char)client.read());
  }

  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  Serial.println("done");
  
  delay(300000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}

The if-available check happens after sending the request, expecting an immediate response; and only happens once. Try this instead

while (client.connected()) {
  if (client.available()) {
    Serial.print((char)client.read());
  } else {
    delay(5);
  }
  // could also add some time check here to exit the loop
}

To encourage the web server to disconnect after sending its response, add this as a request header, after the Host

client.println("Connection: close");

Yes, this works :+1: Just need to implement something to stop while-loop like you said.