User ID: Password: Mail message: File: "> User ID: Password: Mail message: File: ">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Form Data Encoding GET – URL encoded POST – URL encoded

Similar presentations


Presentation on theme: "Form Data Encoding GET – URL encoded POST – URL encoded"— Presentation transcript:

1 Form Data Encoding GET – URL encoded POST – URL encoded
POST – multipart form

2 <form action="/foo" method="get">
User ID: <input type="text" name="userid" size="10" maxlength="8"> Password: <input type="password" name="passwd" size="10" maxlength="8"> Mail message: <textarea name="mmesg" rows="5" cols="40"></textarea> File: <input type="file" name="image_f">

3

4 GET – URL encoding <form action="/foo" method="GET"> ...
some_form.html GET /foo?userid=bkoehler&passwd=foo& mmesg=bow+%26+arrow%0D%0A%3D%0D%0A%3F%3F%3F& image_f=C%3A%5CTEMP%5Ccgi.txt HTTP/1.1 Host: ... HTTP request message

5 POST – URL encoding <form action="/foo" method="POST">
some_form.html POST /foo HTTP/1.1 Host: Content-Type: application/x-www-form-urlencoded Content-Length: 150 userid=bkoehler&passwd=foo& mmesg=bow+%26+arrow%0D%0A%3D%0D%0A%3F%3F%3F& image_f=C%3A%5CTEMP%5Ccgi.txt HTTP request message

6 POST – multipart form <form action="/foo" method="POST"
enctype="multipart/form-data"> some_form.html

7 POST /foo HTTP/1.1 Host: Content-Type: multipart/form-data; boundary=---123 Content-Length: 2421 ---123 Content-Disposition: form-data; name="userid" brian Content-Disposition: form-data; name="passwd" foo Content-Disposition: form-data; name="mmesg" bow & arrow = ???

8 ---123 Content-Disposition: form-data; name="image_f"; filename="cgi.txt" Content-Type: text/plain The contents of the file would be here. HTTP request message

9 The Static Web Doc A Request Origin Server Client Doc B Response Doc C

10 The Dynamic Web ENV Request body Origin Server CGI Program Client
Response Response

11 Common Gateway Interface (CGI)
convention for interaction between web servers and external applications that process requests allows external applications to be reasonably portable across different web servers external programs can be written in any language: C, C++, COBOL, FORTRAN, Java, Assembly, csh, sh, Perl, Python, etc

12 CGI/1.1 overview some information about the HTTP request is passed through environment variables the HTTP request message body (if any) is connected to the external application's standard input stream the external application must generate a valid HTTP response on its standard output stream

13 CGI Environment Variables
HTTP_* most of the headers in the request message get passed as environment variables to the CGI program e.g.: HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, HTTP_USER_AGENT

14 REMOTE_* REMOTE_ADDR REMOTE_HOST
the numeric IP address of the client sending the request this may not be the user agent if there are proxies along the chain REMOTE_HOST the fully qualified domain name of the client sending the request

15 SERVER_* SERVER_SOFTWARE: the name and version of the web server software SERVER_NAME: the server's hostname or IP address SERVER_PORT: the port number the request came in on SERVER_PROTOCOL: the name and version of the protocol the request came in e.g. HTTP/1.1 GATEWAY_INTERFACE: version of CGI, usually CGI/1.1

16 CONTENT_* only generated for POST requests
CONTENT_TYPE: mime type of the message body; usually: application/x-www-form-urlencoded or multipart/form-data CONTENT_LENGTH: length, in characters of the message body

17 Request REQUEST_METHOD: GET, POST, etc.
SCRIPT_NAME: virtual path to script as derived from the URI (no shcheme, host or query component) e.g. /cgi-bin/foo QUERY_STRING: all the text past the '?' in the request URI e.g. arg1=val1&arg2=val2&arg3=val3...

18 Standard Input when the external CGI program starts running, its standard input is connected to the request message at the beginning of the message body: POST /foo HTTP/1.1 Host: Content-Type: application/x-www-form-urlencoded Content-Length: 150 userid=bkoehler&passwd=foo& mmesg=bow+%26+arrow%0D%0A%3D%0D%0A%3F%3F%3F& image_f=C%3A%5CTEMP%5Ccgi.txt

19 POST /foo HTTP/1.1 Host: Content-Type: multipart/form-data; boundary=---123 Content-Length: 2421 ---123 Content-Disposition: form-data; name="userid" brian Content-Disposition: form-data; name="passwd" foo Content-Disposition: form-data; name="mmesg" bow & arrow = ???

20 Standard Output when the external CGI program starts running, anything it writes to standard output will be part of the response to the client modes: non-parsed headers (nph): the CGI program must construct a complete HTTP response message which will be delivered unmodified to the client parsed headers: the web server will fill in any missing required header fields

21 Parsed Headers Content-Type: text/html <html>
... <== output of CGI program HTTP/ OK Date: Mon, 23 Sep :11:21 GMT Server: Apache/ (Unix) PHP/4.0.6 Content-Length: 699 Content-Type: text/html <html> ...

22 Apache mod_cgi two methods of invoking CGI programs:
ScriptAlias directive: all files the specified directory are treated as CGI programs Options +ExecCGI and AddHandler directives: files with specific file extensions are treated as CGI programs


Download ppt "Form Data Encoding GET – URL encoded POST – URL encoded"

Similar presentations


Ads by Google