I was wondering if there was a trick to this I was missing.
On an arduino you do a Get from a web service thusly:
if (client.connect("google.com", 80)) {
client.println("GET /service/v2/time HTTP/1.1");
client.println("Host:nimbits-02.appspot.com");
client.println();
delay(1000);
while(client.connected() && !client.available()) delay(1);
while (client.available()) {
c = client.read();
Serial.print(c);
}
client.stop();
client.flush();
}
Works perfectly fine (calling the nimbits time service)
The content body of this call is what I need, printing the result as above give me:
> HTTP/1.1 200 OK Date: Sat, 02 Feb 2013 17:24:38 GMT Content-Type:
> text/html Server: Google Frontend Content-Length: 13
>
> 1359825878036
All perfectly good – but I have to do some expensive string processing on the arduino to get the message body. I just want 1359825878036. Is there a way to tell the ethernet client to not read the headers? That would be handy.
my best solution so far is to assume the message body is always after the last new line char, which seems error prone:
if (client.connect("google.com", 80)) {
client.println("GET /service/v2/time HTTP/1.1");
client.println("Host:nimbits-02.appspot.com");
client.println();
delay(1000);
while(client.connected() && !client.available()) delay(1);
while (client.available()) {
c = client.read();
response= response + c;
}
int contentBodyIndex = response.lastIndexOf('\n');
if (contentBodyIndex > 0) {
Serial.print(response.substring(contentBodyIndex));
}
client.stop();
client.flush();
}
Thanks, Ben – nimbits.com
Their is a key. The headers end at a double CRLF:
see W3 doc