[ Pobierz całość w formacie PDF ]
.For more about CGI-to-ASP conversion, see Appendix A,48ASP in a Nutshell: A Desktop Quick Reference, eMatter EditionCopyright © 2000 O Reilly & Associates, Inc.All rights reserved.How HTTP WorksFigure 6-1: HELLO.HTM, a simple HTML formFigure 6-2: HELLOCGI.HTM, an HTML page created by a CGI applicationConverting CGI/WinCGI Applications into ASP Applications.) Let s see how thisinterchange between browser and server are handled by the protocol:1.When the user finishes entering the URL for HELLO.HTM, Navigator sends* thefollowing stream to the server:[73:send:(179)]GET /hello.htm HTTP/1.0Connection: Keep-AliveUser-Agent: Mozilla/3.0 (Win95; I)Host: pc229.west.ora.comAccept: image/gif, image/x-xbitmap, image/jpeg,image/pjpeg, */** send in the following output listing is a sockets function that sends a stream in a connectedsocket.In the output, 73 identifies the socket, while 179 is the value returned by the functionand represents the total number of bytes sent.How HTTP Works 49ASP in a Nutshell: A Desktop Quick Reference, eMatter EditionCopyright © 2000 O Reilly & Associates, Inc.All rights reserved.How HTTP WorksThis is a request header.The browser indicates that it wants the server to getthe document /HELLO.HTM.Get is more than a generic description of whatthe server should do; it indicates the HTTP request type.(For details, see HTTP Request Types, later in this chapter.) The browser also indicates thatit s using version 1.0 of the Hypertext Transfer Protocol.Note that the first line in this HTTP header is actually an artifact ofthe TCP/IP packet sniffer used in this demonstration and not part ofthe actual HTTP request sent.The same is true for all HTTP seg-ments in this chapter.2.The server receives* the headers sent by the browser, as shown in thefollowing output produced by our spy program, and processes the request:[21:recv: completed (179)]GET /hello.htm HTTP/1.0Connection: Keep-AliveUser-Agent: Mozilla/3.0 (Win95; I)Host: pc229.west.ora.comAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*3.The server sends the document HELLO.HTM to the browser:[21:send:(535)]HTTP/1.0 200 OKDate: Monday, 30-Sep-98 23:33:00 GMTServer: WebSite/1.1Allow-ranges: bytesAccept-ranges: bytesConnection: Keep-AliveContent-type: text/htmlLast-modified: Monday, 30-Sep-98 23:30:38 GMTContent-length: 297Hello, World!What is your name?Here, WebSite sends a total of 535 bytes to the browser.This consists of aresponse header, followed by a blank line, followed by the HTML documentitself.The header fields indicate, among other things, the number of bytes(the Content-length header) and the format (the Content-type header) of the* The recv function is used to receive data from a socket.In the output, the initial number, 21,represents the socket used by the server. Completed (179) indicates the function s return val-ue, in this case that it completed normally by receiving 179 bytes.Note that this correspondsto the number of bytes sent by the browser.50 Chapter 6 Request ObjectASP in a Nutshell: A Desktop Quick Reference, eMatter EditionCopyright © 2000 O Reilly & Associates, Inc.All rights reserved.How HTTP Workstransmitted data. 200 OK is a status code indicating that the browser srequest was fulfilled.The server also indicates that, like the browser, it s usingversion 1.0 of HTTP.4.The browser reads the headers and data sent by the server:[73:recv: posted][73:recv: completed (260)]HTTP/1.0 200 OKDate: Monday, 30-Sep-98 23:33:00 GMTServer: WebSite/1.1Allow-ranges: bytesAccept-ranges: bytesConnection: Keep-AliveContent-type: text/htmlLast-modified: Monday, 30-Sep-98 23:30:38 GMTContent-length: 297H[73:recv: posted][73:recv: completed (275)]ello, World!What is your name?Although two recv operations are required to retrieve the header recordsalong with the document, the total number of bytes read in these two opera-tions equals the total number of bytes sent by the server.5
[ Pobierz całość w formacie PDF ]