Arduino GSM POST request

Hello everyone!
I'm a student and i bought the GSM Shield (here), tomorrow i'll have it, but i need to configurate it in less than two hours because we have to do a urgent project.

Can someone tell me if this sketch should work? I want to send humidity and temperature value to www.servizi.vilfredo.it in the path /update... here is the part of the code with the POST request:

void InvioDati (String Dato){
  if (client.connect(sito,80)) {
    Serial.println("Connessione...");
    client.println("POST /update HTTP/1.1");
    client.println("Host: servizi.vilfredo.it");
    client.println("Connection: close");
    client.print("X-VILFREDO-KEY:");
    client.println(APIKEY);
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length:");
    client.println(Dato.length());
    client.println();
    client.println(Dato);
    }
  else {
    Serial.println("Connessione fallita");
    Serial.println();
    Serial.println("Disconnessione in corso");
    client.stop();
  }
}

Do you think it should work?

I have another question: what does client.stop() means?
I know that it disconnect from the server, but it automatically reconnect when i do the post request?

Thank you for the support.
Luca.

Can someone tell me if this sketch should work?

No, since you did not post all of it.

I’m sorry, this is the full code:

#include <GSM.h>
#include <DHT.h>
#define APIKEY "....." 
#define PINNUMBER "" // PIN NUMBER 
#define GPRS_APN ""
#define GPRS_LOGIN ""
#define GPRS_PASSWORD ""
#define DHTPIN 5     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE);
GSMClient client;       
GPRS gprs;              
GSM gsmAccess;          
GSM_SMS sms;            

char sito[]= "servizi.vilfredo.it";

boolean Connesso=false;
const unsigned long Intervallo= 298000;
float Temperatura;   
float Umidita;  
float Tem;
float Umi;
long i=1;
long j=0;
long conta;

void setup() {
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  while (!Serial) {
    ;
  }
  Serial.println("Starting Arduino web client.");

  boolean NonConnesso=true;
  while(NonConnesso){
      if((gsmAccess.begin(PINNUMBER)==GSM_READY)&&
          (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)){
            NonConnesso = false;}
      else{
          Serial.println("Non connesso");
          delay(1000); 
        }
    }
    Serial.println("GSM inizializzato");  
}


void loop() {
   
  Tem=dht.readTemperature();
  Umi=dht.readHumidity();
  Temperatura=Temperatura+Tem;
  Umidita=Umidita+Umi;
  conta=millis()/i;
  j++;
  if (client.available()){
    char c= client.read();
    Serial.print(c);
  }
  if (!client.connected() && Connesso){
    client.stop();  
  }
  if (!client.connected() && (conta>Intervallo)){
    Temperatura=Temperatura/j;
    Umidita=Umidita/j;
    String StrTEMP= String(Temperatura);
    String StrHUM= String(Umidita);
    InvioDati("field1="+StrTEMP+"field2"+StrHUM+"&**********"); 
   }
  Connesso=client.connected();
}
  void InvioDati (String Dato){
  if (client.connect(sito,80)) {
    Serial.println("Connessione...");
    client.println("POST /update HTTP/1.1");
    client.println("Host: servizi.vilfredo.it");
    client.println("Connection: close");
    client.print("X-VILFREDO-KEY:");
    client.println(APIKEY);
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length:");
    client.println(Dato.length());
    client.println();
    client.println(Dato);
    }
  else {
    Serial.println("Connessione fallita");
    Serial.println();
    Serial.println("Disconnessione in corso");
    client.stop();
  }
  Umidita=0;
  Temperatura=0;
  i++;
  j=0;
}

Thank you

The only thing obviously wrong with the code is the one letter global variable names that convey no meaning. Why not use a name for j that indicates that it is counting temperature and humidity readings for the purpose of averaging them? Why make people study the code to figure that out?

Well you are right...
I do the same thing in scripts in Python and when i open them after months i can't understand what i wrote :confused:

Anyway, the last question: if i use the SIM of my smartphone, what should i write in APN LOGIN and APN PASSWORD? i have only the apn wap.tim.it, but i don't know user and psw....

Thank you for suggestions!