Danh mục

Web Client Programming with Perl-Chapter 2: Demystifying the Browser-P2

Số trang: 18      Loại file: pdf      Dung lượng: 111.98 KB      Lượt xem: 10      Lượt tải: 0    
Thu Hiền

Hỗ trợ phí lưu trữ khi tải xuống: 20,000 VND Tải xuống file đầy đủ (18 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu web client programming with perl-chapter 2: demystifying the browser-p2, công nghệ thông tin, quản trị web phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Web Client Programming with Perl-Chapter 2: Demystifying the Browser-P2 Chapter 2: Demystifying the Browser-P2When you fill out a form, the browser needs to send that information to theserver, along with the name of the program needed to process it. Theprogram that processes the form information is called a CGI program. Letslook at how a browser makes a request from a form. Lets direct our browserto contact our hypothetical server and request the document /search.html:GET /search.html HTTP/1.0Connection: Keep-AliveUser-Agent: Mozilla/3.0Gold (WinNT; I)Host: hypothetical.ora.comAccept: image/gif, image/x-xbitmap, image/jpeg,image/pjpeg, */*The server responds with:HTTP/1.0 200 OKDate: Fri, 04 Oct 1996 14:33:43 GMTServer: Apache/1.1.1Content-type: text/htmlContent-length: 547Last-modified: Tue, 01 Oct 1996 08:48:02 GMTLibrary SearchEnter book title, author, or subject here: Title Author SubjectKeywords:Press DONE to start your search.The formatted document is shown in Figure 2-4.Figure 2-4. A HTML form rendered in the browserLets fill out the form and submit it, as shown in Figure 2-5. Figure 2-5. Filling out the formAfter hitting the Done button, the browser connects to hypothetical.ora.comat port 80, as specified with the tag in the HTML:The browser then sends:POST /cgi-bin/query HTTP/1.0Referer: http://hypothetical.ora.com/search.htmlConnection: Keep-AliveUser-Agent: Mozilla/3.0Gold (WinNT; I)Host: hypothetical.ora.comAccept: image/gif, image/x-xbitmap, image/jpeg,image/pjpeg, */*Content-type: application/x-www-form-urlencodedContent-length: 47querytype=subject&queryconst=numerical+analysisIn the previous example retrieving the initial page at hypothetical.ora.com,we showed a series of lines that the browser output and called it a requestheader. Calling it a header might not have made any sense at the time, sincethere was no content being sent with it--if youre just requesting a document,you dont have to tell the server anything else. But since in this instance wehave to tell the server what the user typed into the form, we have to use abody portion of the message to convey that information. So there are a fewnew things to note in this example:  Instead of GET, the browser started the transaction with the string POST. GET and POST are two types of request methods recognized by HTTP. The most important thing that POST tells the server is that there is a body (or entity) portion of the message to follow. The browser used the POST method because it was specified in the tag:  The browser included an extra line specifying a Content-type. This wasnt necessary in the previous example because no content was being sent with the request. The Content-type line tells the server what sort of data is coming so it can determine how best to handle it. In this case, it tells the server that the data to be sent is going to be encoded using the application/x-www-form-urlencoded format. This format specifies how to encode special characters, and how to send multiple variables and values in forms. See Chapter 3 and Appendix B, Reference Tables, for more information on URL encoding.  The browser included another line specifying a Content-length. Similarly, this wasnt necessary earlier because there was no content to the entity body. But there is in this example; it tells the server how much data to retrieve. In this case, the Content-length is 47 bytes.  After a blank line, the entity-body is issued, reading querytype=subject&queryconst=numerical+analysis. (Notice that this string is exactly 47 characters, as specified in the Content-length line.)Where did this querytype=subject&queryconst=numerical+analysis linecome from? In the HTML of the form, the input field was specified with thefollowing lines: SubjectThe NAME=querytype and VALUE=subject part of the first tag was encoded as querytype=subject. TheNAME=queryconst part of the second tag specifies avariable name to use for whatever text is supplied in that field. We filled inthat field with the words numerical analysis. Thus, for the form dataentered by the user, the browser sends:querytype=subject&queryconst=numerical+analysisto specify the variable and value pairs used in the form. Two or morevariable/value pairs are separated with an ampersand (&). Notice that thespace between numerical and analysis was replaced by a plus sign (+).Certain characters with special meaning are translated into a commonlyunderstood format. The complete rundown of these transformations iscovered in Appendix B.At this point, the server processes the request by forwarding this informationon to the CGI program. The CGI program then returns some data, and theserver passes it back to the client as follows:HTTP/1.0 200 OKDate: Tue, 01 Oct 1996 14:52:06 GMTServer: Apache/1.1.1Content-type: text/htmlContent-length: 760Last-modified: Tue, 01 Oct 1996 12:46:15 GMTSearch ResultsSearch criteria too wide.Refer to: 1 ASYMPTOTIC EXPANSIONS 2 BOUNDARY ELEMENT METHODS 3 CAUCHY PROBLEM--NUMERICAL SOLUTIONS 4 CONJUGATE DIRECTION METHODS 5 COUPLED PROBLEMS COMPLEX SYSTEMS--NUMERICAL SOLUTIONS 6 CURVE FITTING 7 DEFECT CORRECTION METHODS NUMERICALANALYSIS 8 DELAY DIFFERENTIAL EQUATIONS--NUMERICALSOLUTIONS 9 DIFFERENCE EQUATIONS--NUMERICAL SOLUTIONS 10 DIFFERENTIAL ALGEBRAIC EQUATIONS--NUMERICAL SOLUTIONS 11 DIFFERENTIAL EQUATIONS HYPERBOLIC--NUMERICAL SOLUTIONS 12 DIFFERENTIAL EQUATIONS HYPOELLIPTIC--NUMERICAL SOLUTIONS 13 DIFFERENTIAL EQUATIONS NONLINE ...

Tài liệu được xem nhiều: