We are getting an intermittent (anywhere from 1/20 to 1/5) 400 Bad Request/408 Timeout errors.
Communication is between a Spark Core and Uniform Server XI running on a Windows x64 machine.
Core sends a PUT request via the following code:
/*----------Server Varables----------*/
byte server[] = {000, 000, 000, 000};
String line1("PUT /get_test.php HTTP/1.1\r\n");
String line2("User-Agent: A Spark Core\r\n");
String line3("Host: 000.000.000.000\r\n");
String line4("Connection: close\r\n");
String line5("Content-Type: text/plain\r\n");
String line6("Content-Length: ");
//line 7 is generated
String line8("\r\n");
String line9("\r\n");
String line10("\r\n");
/*-----------------------------------*/
And:
TCPClient client;
if(client.connect(server, 80)) {
client.write( (uint8_t*)line1.c_str(), line1.length() );
client.write( (uint8_t*)line2.c_str(), line2.length() );
client.write( (uint8_t*)line3.c_str(), line3.length() );
client.write( (uint8_t*)line4.c_str(), line4.length() );
client.write( (uint8_t*)line5.c_str(), line5.length() );
client.write( (uint8_t*)line6.c_str(), line6.length() );
client.write( (uint8_t*)line7.c_str(), line7.length() );
client.write( (uint8_t*)line8.c_str(), line8.length() );
client.write( (uint8_t*)line9.c_str(), line9.length() );
delay(20);
client.write( (uint8_t*)message.c_str(), message.length() );
client.write( (uint8_t*)line10.c_str(), line10.length() );
delay(20);
//Serial.println("PUT request sent");
//Serial.print("Data Sent");
int i = 0;
while(client.available()){
if(i == 0) {
Serial.println("entered loop ");
i = 1;
}
char c = client.read();
Serial.print(c);
}
}
client.flush();
client.stop();
delay(100);
}
The Apache logs look (more or less) like this:
[12/Aug/2014:16:09:18 -0400] "PUT /get_test.php HTTP/1.1" 200 - "-" "A Spark Core"
[12/Aug/2014:16:09:28 -0400] "PUT /get_test.php HTTP/1.1" 400 226 "-" "A Spark Core"
[12/Aug/2014:16:23:33 -0400] "PUT /get_test.php HTTP/1.1" 408 221 "-" "A Spark Core"
The error is neither regular nor reliably triggered. Delays between transmits have ranged from 30 seconds to 5 seconds with very little difference in result. Delays after client.stop()
have had no effect.
Another side effect is that the server return is not read by the while loop, although the server does send back an html response.
Any insight or feedback is appreciated.