Danh mục

Web Client Programming with Perl-Chapter 3: Learning HTTP- P2

Số trang: 27      Loại file: pdf      Dung lượng: 106.48 KB      Lượt xem: 12      Lượt tải: 0    
10.10.2023

Hỗ trợ phí lưu trữ khi tải xuống: 9,000 VND Tải xuống file đầy đủ (27 trang) 0
Xem trước 3 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 3: learning http- 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 3: Learning HTTP- P2 Chapter 3: Learning HTTP- P2PUT: Store the Entity-Body at the URLWhen a client uses the PUT method, it requests that the included entity-bodyshould be stored on the server at the requested URL. With HTML editors, itis possible to publish documents onto the server with a PUT method.Revisiting the PUT example in Chapter 2, we see an HTML editor withsome sample HTML in the editor (see Figure 3-5). Figure 3-5. HTML editorThe user saves the document in C:/temp/example.html and publishes it tohttp://publish.ora.com/ (see Figure 3-6). Figure 3-6. Publishing the documentWhen the user presses the OK button, the client contacts publish.ora.com atport 80 and then sends:PUT /example.html HTTP/1.0Connection: Keep-AliveUser-Agent: Mozilla/3.0Gold (WinNT; I)Pragma: no-cacheHost: publish.ora.comAccept: image/gif, image/x-xbitmap, image/jpeg,image/pjpeg, */*Content-Length: 307 This is a headerThis is a simple html document.The server stores the clients entity-body at /example.html and then respondswith:HTTP/1.0 201 CreatedDate: Fri, 04 Oct 1996 14:31:51 GMTServer: HypotheticalPublish/1.0Content-type: text/htmlContent-length: 30The file was created.You might have noticed that there isnt a Content-type header sent withthe browsers request in this example. Its bad style to omit the Content-type header. The originator of the information should describe whatcontent type the information is. Other applications, like AOLpress forexample, include a Content-type header when publishing data withPUT.In practice, a web server may request authorization from the client. Mostwebmasters wont allow any arbitrary client to publish documents on theserver. When prompted with an authorization denied response code, thebrowser will typically ask the user to enter relevant authorizationinformation. After receiving the information from the user, the browserretransmits the request with additional headers that describe theauthorization information.DELETE: Remove URLSince PUT creates new URLs on the server, it seems appropriate to have amechanism to delete URLs as well. The DELETE method works as youwould think it would.A client request might read:DELETE /images/logo22.gif HTTP/1.1The server responds with a success code upon success:HTTP/1.0 200 OKDate: Fri, 04 Oct 1996 14:31:51 GMTServer: HypotheticalPublish/1.0Content-type: text/htmlContent-length: 21URL deleted.Needless to say, any server that supports the DELETE method is likely torequest authorization before carrying through with the request.TRACE: View the Clients Message Through the Request ChainThe TRACE method allows a programmer to see how the clients message ismodified as it passes through a series of proxy servers. The recipient of aTRACE method echoes the HTTP request headers back to the client. Whenthe TRACE method is used with the Max-Forwards and Via headers, aclient can determine the chain of intermediate proxy servers between theoriginal client and web server. The Max-Forwards request headerspecifies the number of intermediate proxy servers allowed to pass therequest. Each proxy server decrements the Max-Forwards value andappends its HTTP version number and hostname to the Via header. A proxyserver that receives a Max-Forwards value of 0 returns the clients HTTPheaders as an entity-body with the Content-type of message/http. Thisfeature resembles traceroute, a UNIX program used to identify routersbetween two machines in an IP-based network. HTTP clients do not send anentity-body when issuing a TRACE request.Figure 3-7 shows the progress of a TRACE request. After the client makesthe request, the first proxy server receives the request, decrements the Max-Forwards value by one, adds itself to a Via header, and forwards it to thesecond proxy server. The second proxy server receives the request, addsitself to the Via header, and sends the request back, since Max-Forwardsis now 0 (zero).OPTIONS: Request Other Options Available for the URL Figure 3-7. A TRACE requestWhen a client request contains the OPTIONS method, it requests a list ofoptions for a particular resource on the server. The client can specify a URLfor the OPTIONS method, or an asterisk (*) to refer to the entire server. Theserver then responds with a list of request methods or other options that arevalid for the requested resource, using the Allow header for an individualresource, or the Public header for the entire server. Figure 3-8 shows anexample of the OPTIONS method in action. Figure 3-8. An OPTIONS requestVersions of HTTPOn the same line where the client declares its method, it also declares theURL and the version of HTTP that it conforms to. Weve already discussedthe available request methods, and we assume that youre already familiarwith the URL. But what about the HTTP version number? For example:GET /products/toothpaste/index.html HTTP/1.0In this example, the client uses HTTP version 1.0.In the servers response, the server also declares the HTTP version:HTTP/1.0 200 OKBy specifying the version number in both the client request and serverresponse, the client and server can communicate on a common denominator,or in the worst case scenario, recognize that the transaction is not possibledue to version conflicts. (For example, an HTTP/1.0 client might have aproblem communicating with an HTTP/0.9 server.) If a server is capable ofunderstanding a version of HTTP higher than 1.0, it should still be able toreply with a format that HTTP/1.0 clients can understand. Likewise, clientsthat understand a superset of a servers HTTP should send requestscompliant with the servers version of HTTP.While there are similarities among the d ...

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