How to get the data from server with TCPClient.read()

Hi.
I’ve been trying to use TCPClient.read() to get the data from WEB server,but not work.

Clent:

TCPClient client;
byte server[] = { xx, xx, xx, xx};
void setup() {
    Serial.begin(9600);
    while(!Serial.available()) Particle.process();

    if (client.connect(server, 80))
    {        
        client.println("POST /xxxxxxxx.php HTTP/1.0");
        client.println("Host:www.xxxxxx.xxxxxx");
        client.println("Content-Type: application/x-www-form-urlencoded");
        client.println("Content-Length:54");
        client.println();
        client.println("action=Sensor&Latitude=35.000000&Longitude=135.000000");
        client.println();
    }
    else
    {
        Serial.println("connection failed");
    }
}

void loop() {
    int n = client.available();    
    if (n)
    {
        for( int i =0; i < n; i ++ )
        {
            char c = client.read();
            Serial.print(c);
        }        
    } 
}

When server side php code:

<?php                                                                                                                     
    require_once "HTTP/Request.php"; 
    print('abcdefghijklmnopqrstuvwxyz');
    print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    print('abcdefghijklmnopqrstuvwxyz');
    print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    print('12');
?>

Result:

HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:00:41 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Connection: close
Conten

…Short.

When server side php code:

<?php                                                                                                                     
    require_once "HTTP/Request.php"; 
    print('abcdefghijklmnopqrstuvwxyz');
    print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    print('abcdefghijklmnopqrstuvwxyz');
    print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    print('123')
?>

Result:

HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:03:37 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Connection: close
Content-Type: text/html

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123

…OK.

When server side php code:

<?php                                                                                                                     
    require_once "HTTP/Request.php"; 
    print('abcdefghijklmnopqrstuvwxyz');
    print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    print('abcdefghijklmnopqrstuvwxyz');
    print('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    print('1234')
?>

Result:

HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:06:20 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Connection: close
Content-Type: text/html

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123

…Short.

When server side php code:

<?php                                                                                                                     
    require_once "HTTP/Request.php"; 
?>

Result:

HTTP/1.1 200 OK
Date: Sat, 12 Mar 2016 04:12:12 GMT
Server: Apache/2.2.31
X-Powered-By: PHP/5.2.17
Content-Length: 0
Connec

…Short.

What am I doing wrong?

I would say, add a little delay to give the buffer a chance to fill up.

Thank you peter_a.

I tried to this code to add a little delay.
But not good.

void loop() {
    if( client.available() )
    {
            char c = client.read();
            Serial.print(c);
    } 
}

Just guessing: What about output buffering? Do you need to insert a

flush();

after the last print statement in the PHP server code? This might be necessary because the data doesn’t end with a linefeed character.

Thank you rickkas7.
I inserted a flash statment after the last print statment.
But not good.