Unstable Send Post Method

Please help why this line of code only reach "Connected to Server"?

const char *ServerTarget = "192.168.254.102";
EthernetClient client;
  String data = "mobileno=" + cellno + "&respond=" + respond;
  if (client.connect(ServerTarget,80)) {
      Serial.println("Connected to server");
      client.println();
      client.println("POST /xxx/index.php/dashboard/smsrespond HTTP/1.1");
      client.println("Host: 192.168.254.102");
      client.println("Content-Type: application/x-www-form-urlencoded");
      client.print("Content-Length: ");
      client.println(data.length());
      client.println();
      client.println(data);
      client.println();
  }

Here is the whole code…

#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xED};

const char mobileno[13] = "";
const char txtmessage[30] = "";
char sendernum[13] = "";
const char *ServerTarget = "192.168.254.102";

EthernetServer server(80);
SoftwareSerial SIM900A(7,8);

String readString = String(30);
String inchar = String(30);
char phone[14] = "";
char txt[30] = "";
String mobile_ = "";
String msg_ = "";
String mobile_msg;
String data;
int start;
int ind1; 
int ind2;
String currentLine = "";

IPAddress local_IP(192, 168, 254, 152);
IPAddress gateway(192, 168, 254, 254);
IPAddress subnet(255, 255, 255, 0);

void setup()
{ 
  delay(1000);
  SIM900A.begin(9600);   
  Serial.begin(9600);    
  delay(100);
  Serial.println ("SIM900A Ready");
  delay(100);
  Ethernet.begin(mac);
  delay(500);
  server.begin();
  delay(500);
  Serial.println("Server is at");
  Serial.println(Ethernet.localIP());
  delay(1000);
  SendMessage("09277324510","HOVER GSM has been turned on!");
  delay(5000);
}

void loop()
{ 
  if (SIM900A.available()>0){
        String k=SIM900A.readString();
        Serial.println( "This one:" + k );
        int beginposition = k.indexOf("+63");
        String temp_sendernum = k.substring( beginposition, beginposition+13 );
        temp_sendernum.toCharArray(sendernum,14);
        temp_sendernum.trim();
        Serial.println( temp_sendernum );
        if(k.indexOf("Yes") > -1 || k.indexOf("YES") > -1 || k.indexOf("yes") > -1){
            if(temp_sendernum.length()>0){
              Serial.println("Replied: YES\r");    
              SendDataToServer(temp_sendernum,"Accept");
              delay(2000);
              SendMessage(sendernum,"Thank you..!");
              delay(1000);
              //delete messages...
              SIM900A.print("AT+CMGD=1,4");
            }
        }
        else if (k.indexOf("No") > -1 || k.indexOf("NO") > -1 || k.indexOf("no") > -1){
            if(temp_sendernum.length()>0){
              Serial.println("Replied: NO\r");
              SendDataToServer(temp_sendernum,"Decline");
              delay(2000);
              SendMessage(sendernum,"Okay! Thank you...!");
              delay(1000);
            }
        }
  }

  delay(100);
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (readString.length() < 100) {
          readString += c;
        }      
        if (c == '\n') {
          Serial.println(readString); 
          //now output HTML data header
             if(readString.indexOf('?') >=0) { 
               client.println("HTTP/1.1 204 Zoomkat");
               client.println(); 
             }
             else {
          client.println("HTTP/1.1 200 OK"); 
          client.println("Content-Type: text/html");
          client.println();
             }
          delay(1);
          client.stop();
          Serial.println("client disconnected.");
          Serial.println("Data from server captured in readString:");
          Serial.print(readString); 
          start = readString.indexOf("?phone");  
          ind1 = readString.indexOf('=', start+2);  
          ind2 = readString.indexOf("&d", ind1+1 );  
          data = readString.substring(ind1+1, ind2);   
          Serial.print("my data is: ");
          Serial.println(data);
          mobile_msg = data;
          data=""; 
          readString="";
          mobile_ = mobile_msg.substring(0,11);
          mobile_.toCharArray(phone,13);
          delay(100);
          SendMessage(phone , "HOVER: You have a visitor or delivery coming. Reply [Yes/No] within 2 minutes to accept or not.");
          delay(100);
        }
      }
    }
  }

}

 void SendMessage(char mobile_number[13], char txt_message[100])
{
    Serial.println("Sending Message...");
    SIM900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
    delay(2000);
    Serial.println("Set SMS Number");
    SIM900A.println(String("AT+CMGS=\"") + mobile_number + String("\"\r")); 
    delay(2000);
    Serial.println("Set SMS Content");
    SIM900A.println( txt_message );
    delay(2000);
    Serial.println("Finish");
    SIM900A.println((char)26);
    delay(500);
    Serial.println("Message has been sent!");
}

void SendDataToServer(String cellno, String respond)
{
  EthernetClient client;
  data = "mobileno=" + cellno + "&respond=" + respond;
  if (client.connect(ServerTarget,80)) {
      Serial.println("Connected to server");
      client.println("POST /lendiotech/index.php/dashboard/smsrespond HTTP/1.1");
      client.println("Host: 192.168.254.102");
      client.println("Content-Type: application/x-www-form-urlencoded");
      client.print("Content-Length: ");
      client.println(data.length());
      client.println(data);
      client.stop();
  }
 else{
  Serial.print("Not Connected \n");
  }
  
  }

that's wrong for sure:

client.print("Content-Length: "); client.println(data.length()); client.println(data);

here is the client.println() missing.

It is not what I told you in #1 body (data) needs to be separated from header.

Thanks for your answer.

I tried already!! Still unstable. Sometimes it send a post, sometimes not.

When it actually arrives to the server/host it stores the information to the database. And in my codeigniter code, there's no problem. It just that it hangs or freeze on arduino end after the "Connected to Server" line. I don't know why. But when I do it again (reply via SMS), it works and sometimes won't.

The flow is actually, when I made a reply on my GSM I will store the replied info to the database. I can see that my GSM works well, coz it prints info on my serial and I also received confirmation info via SMS too. Only on the part or function SendDataToServer() not working sometimes. Really unstable...