Loading video...
HTTP & the POST Method
-
HTTP request and HTTP response messages are compsed of two parts, which are separated by a
blank line:
- a message header
- a message body
- HTTP request headers have a required first line followed by an optional number of what are known as HTTP
headers. The first line must contain the HTTP method, the requested URI, and the HTTP version. An example HTTP
request header containing the
HostHTTP header is:GET /index.html HTTP/1.1
Host: www.educator.com - HTTP response headers have a required first line followed by an optional number of HTTP headers. The first line
must contain the HTTP version, HTTP status code, and phrase describing the status code. An example HTTP
response message (both header and body) is:
HTTP/1.1 200 OK
Date: Wed, 3 Aug 2011 23:59:59 GMT
Content-Length: 31
Content-Type: text/html
[blank line]
<html><body>Hello</body></html> header()allows you to manually add HTTP headers to the HTTP response generated by your PHP script, and it must be called before ANY output from a PHP script has been generated (if output buffering isOff).- The
GETmethod works by appending any data to the URL via a query string. ThePOSTmethod rather includes submitted data in the body of the HTTP request. By default,POSTdata is URL-encoded, just as for a query string. Here is an example of aPOSTrequest containing data:POST /contactUs.php HTTP/1.1
Host: store.educator.com
Date: Wed, 3 Aug 2011 23:59:59 GMT
Content-Length: 39
Content-Type: application/x-www-form-urlencoded
[blank line]
name=Joe+Smith&email=jsmith@hotmail.com POSTdata is accessed from PHP using the$_POSTsuperglobal.- The
GETmethod is typically used for simple resource requests or performing a query/search. ThePOSTmethod is typically reserved for idempotent requests, or requests that have no side-effects. - Additional Resources:
HTTP & the POST Method
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.



































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview