MKR1400-how do I troubleshoot a POST request?

I'm trying to send a POST request to an online server, but failing to connect. How can I troubleshoot/debug the connection?

Code follows:

#include <MKRGSM.h>
#include <ArduinoJson.h>

GSMSSLClient client;

GPRS gprs;

GSM gsmAccess;

// Specify IP address or hostname

char server[] = "webhook.site/ce480c43-95a8-4f1e-b996-bc02f6d1adaa";
int port = 443; // port 443 is the default for HTTPS
DynamicJsonDocument doc(1024);

void setup() {
  bool connected = false;  
  while (!connected) {

  if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&

       (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {

    connected = true;
    Serial.println("Connected");


   } else {

     Serial.println("Not connected");

     delay(1000);

   }
 }
}
...

  doc["latitude"] = latitude;
  doc["longitude"] = longitude;
  doc["altitude"] = altitude;
  
  String location;
  serializeJson(doc, location);

if (client.connect(server, port)) {
    client.print("POST ");
    client.print("https://");
    client.print(server);
    client.println(" HTTP/1.1");
    client.println("Content-Type: application/json;");
    client.println();
    client.println(location);
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }

With

GSM gsmAccess(true);

and then watch the serial monitor.

Thank you.

This
This is the output I got on the serial monitor. I'm not sure how to parse it.

I am not seeing a POST request on the webhook site.

Starting Arduino web client.
TAT

OK
AT+IPR=921600

OK
AT

OK
AT+UPSV=3

OK
AT+CPIN?

ERROR
AT+CPIN?

+CPIN: READY

OK
AT+CMGF=1

OK
AT+UDCONF=1,1

OK
AT+CTZU=1

OK
AT+UDTMFD=1,2

AT+CREG?

+CREG: 0,0

OK

+UMWI: 0,1

+UMWI: 0,2

+UMWI: 0,3

+UMWI: 0,4


AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,5

OK
AT+UCALLSTAT=1

OK
AT+CGATT=1

OK
AT+UPSD=0,1,"prepay.pelion"

OK
AT+UPSD=0,6,3

OK
AT+UPSD=0,2,"arduino"

OK
AT+UPSD=0,3,"arduino"

OK
AT+UPSD=0,7,"0.0.0.0"

OK
AT+UPSDA=0,3

OK
AT+UPSND=0,8

+UPSND: 0,8,1

OK
Connected
AT+USECMNG=0,0,"AddTrust_External_CA_Root",1082
>
+USECMNG: 0,0,"AddTrust_External_CA_Root","1d3554048578b03f42424dbf20730a3f"

OK
AT+USECMNG=0,0,"Baltimore_CyberTrust_Root",891
>
+USECMNG: 0,0,"Baltimore_CyberTrust_Root","acb694a59c17e0d791529bb19706a6e4"

OK
AT+USECMNG=0,0,"COMODO_RSA_Certification_Authority",1500
>
+USECMNG: 0,0,"COMODO_RSA_Certification_Authority","1b31b0714036cc143691adc43efdec18"

OK
AT+USECMNG=0,0,"DST_Root_CA_X3",846
>
+USECMNG: 0,0,"DST_Root_CA_X3","410352dc0ff7501b16f0028eba6f45c5"

OK
AT+USECMNG=0,0,"DigiCert_High_Assurance_EV_Root_CA",969
>
+USECMNG: 0,0,"DigiCert_High_Assurance_EV_Root_CA","d474de575c39b2d39c8583c5c065498a"

OK
AT+USECMNG=0,0,"Entrust_Root_Certification_Authority",1173
>
+USECMNG: 0,0,"Entrust_Root_Certification_Authority","d6a5c3ed5ddd3e00c13d87921f1d3fe4"

OK
AT+USECMNG=0,0,"Equifax_Secure_Certificate_Authority",804
>
+USECMNG: 0,0,"Equifax_Secure_Certificate_Authority","67cb9dc013248a829bb2171ed11becd4"

OK
AT+USECMNG=0,0,"GeoTrust_Global_CA",856
>
+USECMNG: 0,0,"GeoTrust_Global_CA","f775ab29fb514eb7775eff053c998ef5"

OK
AT+USECMNG=0,0,"GeoTrust_Primary_Certification_Authority_G3",1026
>
+USECMNG: 0,0,"GeoTrust_Primary_Certification_Authority_G3","b5e83436c910445848706d2e83d4b805"

OK
AT+USECMNG=0,0,"GlobalSign",958
>
+USECMNG: 0,0,"GlobalSign","9414777e3e5efd8f30bd41b0cfe7d030"

OK
AT+USECMNG=0,0,"Go_Daddy_Root_Certificate_Authority_G2",969
>
+USECMNG: 0,0,"Go_Daddy_Root_Certificate_Authority_G2","803abc22c1e6fb8d9b3b274a321b9a01"

OK
AT+USECMNG=0,0,"VeriSign_Class_3_Public_Primary_Certification_Authority_G5",1239
>
+USECMNG: 0,0,"VeriSign_Class_3_Public_Primary_Certification_Authority_G5","cb17e431673ee209fe455793f30afa1c"

OK
AT+USECMNG=2,0,"AmazonRootCA1"

ERROR
AT+USECMNG=0,0,"Starfield_Services_Root_Certificate_Authority_G2",1011
>
+USECMNG: 0,0,"Starfield_Services_Root_Certificate_Authority_G2","173574af7b611cebf4f93ce2ee40f9a2"

OK
AT+USOCR=6

+USOCR: 0

OK
AT+USOSEC=0,1,0

OK
AT+USECPRF=0,0,1

OK
AT+USOCO=0,"webhook.site",443

ERROR
AT+USOCL=0

ERROR
connection failed

Welcome to the club! I'm already fighting a long battle on this field of shame...

AT+USOCO=0,"webhook.site",443

Means the modem failed creating a socket to webhook.site on port 443.

ERROR
AT+USOCL=0

The modem answers ERROR...how exciting...
Then tries to close the never opened socket. Answer is ERROR

So, this is the core of the problem. The baseband (the modem) is a seperate "computer" with firmware etc. You can only communicate with AT commands but you can never control or debug whats happening between the modem and the network.

I see. Is there anything else that can be done here?

What all programmers do. Find the bug, don't lose your nerve... Good luck!