Ethernetclient not sending all data ?

Hey

I seem to have a issue with my ethernetclient, I am trying to post data to my webserver but the piece of code I use seems to only work when in setup, and not in my loop.

It concerns this snippet:

//connection to API server
      if(toAPI.connect(API_IP, 80)>0)
	{
        toAPI.println( "POST /SensorData/ HTTP/1.1" );
        toAPI.println( "Host: 10.10.4.165" );
        toAPI.println( "Content-Type: application/json; charset=UTF-8" );
        toAPI.println( "Connection: keep-alive" );
        toAPI.print( "Content-Length: " );
        toAPI.println( 58 );  //data.length()
        toAPI.println("Cache-Control: max-age=0");
        toAPI.println("Accept-Language: en-US,en;q=0.8");
        toAPI.println();
        toAPI.print( "{\"user_id\" : 1, \"temperature\" :  222.2 , \"heartrate\" : 222}" );  //data
        toAPI.println();
      
         while(toAPI.available()) 
         {
          char c = toAPI.read();
          Serial.print(c);
        }
      }
      else
      {
        Serial.print("NCON");
      }
        
        toAPI.stop();  
        
      
    }

If I check my Apache error.log, I get the following errors:

 [error] [client 10.10.4.170] PHP Notice:  Undefined index: PATH_INFO in /var/www/index.php on line 49
[Wed Nov 28 18:38:17 2012] [error] [client 10.10.4.170] PHP Notice:  Undefined offset: 1 in /var/www/index.php on line 28

(I am checking for $this->url_elements = explode('/', $_SERVER['PATH_INFO']); )

This is what's in my Apache access.log

10.10.4.170 - - [28/Nov/2012:18:38:17 +0100] "POST /SensorData/ HTTP/1.1" 200 574 "-" "-"
10.10.4.170 - - [28/Nov/2012:18:38:17 +0100] "}" 200 131 "-" "-"

I have no idea where the curly bracket comes from, I tried changing the connection: keep-alive to close. Doesn't help.
the toAPI.read() doesn't seem to return anything either.

Does anyone know why the ethernetclient could fail ? the .connect() returns true, and I am seeing a 200 status in my apache. Yet, the PHP script fails.

Just a little addon, if I use this code

 while(toAPI.connected()) {
       // the server will close the connection when it is finished sending packets
       while(toAPI.available()) {
          
          Serial.print(toAPI.read());
           }
        }

The toAPI.read returns things like

72848480474946493250484832797513106897116101583284104117443250573278111118325048495032494858495258534832717784131083101114118101114583265112979910410147504650464952324085981171101161174113108845801111191011141011004566121583280728047534651465045491179811711011611752464956131067111110116101110116457610111010311610458325150531310751011011124565108105118101583211610510910111111711661495344321099712061494848131067111110110101991161051111105832751011011124565108105118101131067111110116101110116458412111210158329711211210810599971161051111104710611511111059329910497114115101116611171161025613101310107811111610599101583285110100101102105110101100321051101001011205832104101971141161149711610132105110324711897114471191191194799111110116114111108108101114115478310111011511111468971169767111110116114111108108101114461121041123211111032108105110101324954101078111116105991015832851101001011021051101011003210511010010112058321161011091121011149711611711410132105110324711897114471191191194799111110116114111108108101114115478310111011511111468971169767111110116114111108108101114461121041123211111032108105110101324954101078111116105991015832851101001011021051101011003210511010010112058321171151011149510510032105110324711897114471191191194799111110116114111108108101114115478310111011511111468971169767111110116114111108108101114461121041123211111032108105110101324954101233410910111511597103101345834841041051153210097116973211997115321151179810910511611610110034125107811111610599101583285110100101102105110101100321051101001011205832806584729573787079321051103247118971144711911911947105110100101120461121041123211111032108105110101325257101078111116105991015832851101001011021051101011003211110210211510111658324932105110324711897114471191191194710511010010112046112104112321111103210810511010132505610

Yea :confused:

Hey Guys/Girls

The issue has been resolved, it was as simple as having a extra space I didn't see in my body, and therefore the content length was incorrect.

Hello and welcome,

Good that you solved it yourself :slight_smile: