Author Topic: Content of an HTTP response  (Read 1148 times)

I'm trying to send some HTML text in response to an HTTP GET request, but I don't know precisely what has to be in the header.

Here's what I have at the moment:

Code: [Select]
HTTP/1.0 200 OK\r\nContent-Type: text/HTML\r\nContent-Length: 29\r\n<html><body>Hai!</body></html>\r\n\r\n

Code: [Select]
// Set the command data
%data = "GET " @ $RSSFeed::serverURL @ " HTTP/1.0\r\n";
%data = %data @ "Host: " @ $RSSFeed::serverName @ "\r\n";
%data = %data @ "User-Agent: " @ $RSSFeed::userAgent @ "\r\n\r\n"

// Send the command to the connected server.
%thisTCPObj.send(%data);

Is that what you're looking for?

Is that what you're looking for?

I'm sending a server response, not a client request.

You can google this pretty easily. I can already see from the line endings alone you've got it wrong.

You can google this pretty easily. I can already see from the line endings alone you've got it wrong.

I did google it. Repeatedly. Everything that turned up was for the requests for the client, not the responses for the server.

I did google it. Repeatedly. Everything that turned up was for the requests for the client, not the responses for the server.
Looks like there's some info here:
https://www.google.com/#safe=off&hl=en&q=http+server+response+format

Try a packet sniffer and examine what happens in an HTTP request.

Code: [Select]
GET /index.php?topic=228524.msg6522468 HTTP/1.1
Host: forum.blockland.us
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://forum.blockland.us/index.php
Cookie: __utma=[snip]; __utmz=[snip].utmccn=(referral)|utmcsr=forum.blockland.us|utmcct=/index.php|utmcmd=referral; PHPSESSID=[snip]
Connection: keep-alive
If-Modified-Since: Fri, 12 Apr 2013 19:51:30 GMT
Cache-Control: max-age=0

Code: [Select]
HTTP/1.1 200 OK
Date: Fri, 12 Apr 2013 19:52:04 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.1.6
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: private
Pragma: no-cache
Last-Modified: Fri, 12 Apr 2013 19:52:04 GMT
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 4197
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1

Very minimal example:

HTTP-Version Response-Code Response-Message\r\nHeader-A: Value-A\r\nHeader-B: Value-B\r\nHeader-C: Value-C\r\n\r\noptional content

"Inflated":

HTTP-Version Response-Code Response-Message
Header-A: Value-A
Header-B: Value-B
Header-C: Value-C

optional content




(these are arbitrary valid headers, the server could send any it wants, don't always rely on specific ones)

HTTP/1.1 200 OK
Date: Mon, 1 Jan 1900 00:00:00 GMT
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Length: 5

hello