end string returned to cURL

Posted on
Tue Sep 30, 2014 1:35 am
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

end string returned to cURL

Need some help in composing the string returned by a self designed web server (minimalistic on a spark / arduino chip)

QUESTION: how do I end the transmission back to the requestor at the server side.

when I do
curl -d "command" --max-time 5 192.x.y.z

my mini server gets "the command" and returns the proper string to curl. curl prints it, but curl still times out waiting for something else.
what do I need to send to end the transmission?

Any pointer to a web page where I can find this is welcome ..

Karl

Posted on
Tue Sep 30, 2014 7:04 am
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: end string returned to cURL

Are you setting the Content-Length HTTP header during your return? You might want to post what headers you are sending back for us to take a quick look.

Adam

Posted on
Tue Sep 30, 2014 8:51 am
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

Re: end string returned to cURL

I am just sending plain text. Also tried <html>text</html>


Sent from my iPhone using Tapatalk

Posted on
Tue Sep 30, 2014 11:02 am
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: end string returned to cURL

If you are implementing your own server you are responsible for sending back a response in the proper HTTP protocol... an example response would be something like this:

Code: Select all
HTTP/1.1 200 OK
Date: Tue, 30 Sep 2014 16:58:00
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Content-Length: [LENGTH RETURNING]
<html>...</html>

You can look up what the values mean -- and there are a ton of headers possible, but that would be a typical set. You may want to end the content with a newline to be safe, though I cannot quite recall if that is required.

Adam

Posted on
Tue Sep 30, 2014 2:14 pm
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

Re: end string returned to cURL

with
Code: Select all
curl -d "{12345678}" --max-time 5 192.x.y.x
#(using the {} as start and end of data indicator)
Code: Select all
                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:
Code: Select all
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


used the most basic header, sending 8 characters, they come through including the empty line after header... what am I doing wrong?

any pointer or advice welcome

Karl

Posted on
Tue Sep 30, 2014 3:24 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: end string returned to cURL

Code: Select all
server.println("HTTP-Version: HTTP/1.0 200 OK");
I don't know if this is your issue, but you don't include the HTTP-Version...

Code: Select all
server.println("HTTP/1.0 200 OK");

Adam

Posted on
Tue Sep 30, 2014 4:14 pm
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

Re: end string returned to cURL

This seems to work..
Code: Select all
                 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("}");




thx Adam

Karl

Code: Select all
curl -d "{1234567890xx}"  --max-time 2  192.168.1.204
{1234567890xx}

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests