Sending http header with simple TCPServer

with

using the {} as start and end of data indicator

and the following code in spark

server.println("HTTP-Version: HTTP/1.0 200 OK");
server.println("Content-Length: 8");
server.println("Content-Type: text/html");
server.print("\r\n");
server.println(buf);  // this is the data received excl the {}

just sending the received data back from the spark, I get:


HTTP-Version: HTTP/1.0 200 OK
Content-Length: 8
Content-Type: text/html

12345678
curl: (28) Operation timed out after 5229 milliseconds with 116 out of -1 bytes received

using the most basic header, sending 8 characters, they come through including the empty line after header… what am I doing wrong? It looks as if the header is not recognized as header, just data (may be)

any pointer or advice welcome

kw

Change that to server.println("HTTP/1.0 200 OK");
and add a server.stop(); to close the connection and you should be fine :smile:

The available() call returns a TCPClient object which comes along with the flow control.

Enjoy! :sunflower:

1 Like

This seems to work…

[code] server.println(“HTTP/1.0 200 OK”);
// server.println("HTTP-Version: HTTP/1.0 200 OK ");
server.print(“Content-Length: “);
server.println(numberOfChar+2);
server.println(“Content-Type: text/plain “);
server.print(”\r\n{”);
server.print(buf);
server.println(”}”);

[/code]

thx
Karl

curl -d "{1234567890xx}" --max-time 2 192.168.1.204 {1234567890xx}

1 Like

error message:‘class TCPServer’ has no member named ‘stop’

This seems to work, need delay, if no “delay(10)” it drops some of the characters … between 1… and all
delay(10);
client.stop();

thx for the help

KW

here the complete code (this section)

server.println("HTTP/1.0 200 OK");
server.print("Content-Length: ");
server.println(numberOfChar+2);
server.println("Content-Type: text/plain ");
server.print("\r\n{");
server.print(buf);
server.println("}");
delay(10);
client.stop();