.Reference: HTTP Message Structures

Category: Internet

Date: 02-16-2022

Return to Index


 
'An HTTP Client opens a connection and sends a request message to an HTTP server
'The server then returns a response message, usually containing the resource that
'was requested.  After delivering the response, the server closes the connection.
 
'An HTTP request and HTTP response reach consist of 4 sections
 
1. Initial Line       'end in crlf
2. Header Line(s)     'end in crlf
3. Blank Line         'crlf
4. Body               '(optional)
 
'Details of these are provided below, but first here is an example of an HTTP
'request and an HTTP response.
 
'SAMPLE HTTP REQUEST
Get http://www.garybeene.com/files/tcp_test.txt HTTP/1.0
From[email protected]
User-Agent: HTTPTool/1.0
[blank Line here]
 
'SAMPLE HTTP RESPONSE  (in response to sample request above)
HTTP/1.1 200 OK
Date: Thu, 01 Oct 2009 03:02:37 GMT
Server: Apache
Last-Modified: Thu, 01 Oct 2009 02:19:54 GMT
ETag: "b24f18a-24-474d648708680"
Accept-Ranges: bytes
Content-Length: 36
Connection: Close
Content-TypeText/plain
 
PowerBASIC provides
Tcp capabilties.
 
'Note: the response includes the header, a blank line, and then the body
'of the response - in this case, the text from the file (just 2 lines of text)
 
 
'INITIAL LINE - 3 parts separated by spaces Method - Path$ - HTTPVersion
Initial Line For a Request:   'Method      RequestedPath$              HTTPVersion
                                Get          /files/gbsnippets.Msg        HTTP/1.0
 
'- Methods include Get, Post, Head, Send (Get is most common)
'- Path is the part of the URL after the host name (also called the URI)
'- The HTTP version always takes the form "HTTP/x.x", uppercase.
 
Initial Line For a Response:   'HTTP Version      Status Code      Description
                                 HTTP/1.0          200               OK
                                 HTTP/1.0          404               Not Found
 
'HEADER LINES
'- One line per header, of the form "Header-Name: value", ending with CRLF (not case-sensitive, white space ignored)
'- Header Lines beginning with space or Tab are actually part of the previous header line, folded into multiple lines For easy reading.
 
Examples of Header Lines:
User-agent: Mozilla/3.0Gold
Last-Modified: Fri, 31 Dec 1999 23:59:59 GMT
 
'BODY
'An HTTP message may have a body of data sent after the header lines. In a response, this
'is where the requested resource is returned to the client (the most common use of the message
'body), or perhaps explanatory text if there's an error. In a request, this is where user-entered
'data or uploaded files are sent to the server.
 
'gbs_00367
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm