A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

Protocolo HTTP. Let us start with this quote from the HTTP specification document [2]: The HTTP protocol is based on a request /response paradigm. A client.

Apresentações semelhantes

Apresentação em tema: "Protocolo HTTP. Let us start with this quote from the HTTP specification document [2]: The HTTP protocol is based on a request /response paradigm. A client."— Transcrição da apresentação:

1 Protocolo HTTP

2 Let us start with this quote from the HTTP specification document [2]: The HTTP protocol is based on a request /response paradigm. A client establishes a connection with a server and sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content. The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta-information, and possible body content.

3 Protocolo HTTP (2) What this means to libwww-perl is that communication always take place through these steps: First a request object is created and configured. This object is then passed to a server and we get a response object in return that we can examine. A request is always independent of any previous requests, i.e. the service is stateless (sem estado). The same simple model is used for any kind of service we want to access.

4 Exemplos 1) if we want to fetch a document from a remote file server, then we send it a request that contains a name for that document and the response will contain the document itself. 2) If we access a search engine, then the content of the request will contain the query parameters and the response will contain the query result. 3) If we want to send a mail message to somebody then we send a request object which contains our message to the mail server and the response object will contain an acknowledgment that tells us that the message has been accepted and will be forwarded to the recipient(s).

5 O objeto Request The libwww-perl request object has the class name The fact that the class name uses as a prefix only implies that we use the HTTP model of communication. It does not limit the kind of services we can try to pass this request to. For instance, we will send both to ftp and gopher servers, as well as to the local file system. The main attributes of the request objects are: The method is a short string that tells what kind of request this is. The most common methods are GET, PUT, POST and HEAD. The uri is a string denoting the protocol, server and the name of the "document" we want to access. The uri might also encode various other parameters. The headers contain additional information about the request and can also used to describe the content. The headers are a set of keyword/value pairs. The content is an arbitrary amount of data.

6 O objeto Response The libwww-perl response object has the class name The main attributes of objects of this class are: The code is a numerical value that indicates the overall outcome of the request. The message is a short, human readable string that corresponds to the code. The headers contain additional information about the response and describe the content. The content is an arbitrary amount of data. Since we don't want to handle all possible code values directly in our programs, a libwww-perl response object has methods that can be used to query what kind of response this is. The most commonly used response classification methods are: is_success() The request was was successfully received, understood or accepted. is_error() The request failed. The server or the resource might not be available, access to the resource might be denied or other things might have failed for some reason.

7 O User Agent (UA) Let us assume that we have created a request object. What do we actually do with it in order to receive a response? The answer is that you pass it to a user agent object and this object takes care of all the things that need to be done (like low-level communication and error handling) and returns a response object. The user agent represents your application on the network and provides you with an interface that can accept requests and return responses. The user agent is an interface layer between your application code and the network. Through this interface you are able to access the various servers on the network.

8 User Agent The class name for the user agent is LWP::UserAgent. Every libwww-perl application that wants to communicate should create at least one object of this class. The main method provided by this object is request(). This method takes an object as argument and (eventually) returns a object. The user agent has many other attributes that let you configure how it will interact with the network and with your application.

9 The timeout specifies how much time we give remote servers to respond before the library disconnects and creates an internal timeout response. The agent specifies the name that your application should use when it presents itself on the network. The from attribute can be set to the address of the person responsible for running the application. If this is set, then the address will be sent to the servers with every request. The parse_head specifies whether we should initialize response headers from the section of HTML documents. The proxy and no_proxy attributes specify if and when to go through a proxy server. URL:http://www.w3.org/pub/WWW/Proxies/ URL:http://www.w3.org/pub/WWW/Proxies/ The credentials provide a way to set up user names and passwords needed to access certain services. Many applications want even more control over how they interact with the network and they get this by sub-classing LWP::UserAgent. The library includes a sub-class, LWP::RobotUA, for robot applications

10 This example shows how the user agent, a request and a response are represented in actual perl code: # Create a user agent object use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); # Create a request my $req = => 'http://search.cpan.org/search'); $req- >content_type('application/x-www-form-urlencoded'); $req->content('query=libwww-perl&mode=dist'); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; } The $ua is created once when the application starts up. New request objects should normally created for each request sent.

11 Capítulo 1 - Introdução

12 Web Client (Cliente Web) Cliente Web: é uma aplicação que comunica-se com um servidor Web usando o protocolo HTTP

13 Cliente Web (2) A interface mais comum a WWW é o navegador (browser) web browser permite que você faça o download de documentos web e veja-os formatados na tela

14 URL (Universal Resource Locator) É um subconjunto da URI (Universal Resource Identifier, ou Identificador de Recursos Universal)

15 HTTP (Hypertext Transport Protocol)

16 Common Gateway Interface (CGI)

17 Capítulo 2 – Desmistificando o Browser

18 Transação HTTP programa web cliente web servidor web o protocolo HTTP é baseado em texto, isto é, podemos ver os comandos sendo trocados transação web

19 A requisição através do browser protocolo usado hypothetical.ora.com servidor / diretório no servidor

20 A requisição do cliente GET / HTTP/1.0 Connection: Keep-Alive User-Agent: Mozilla/3.0Gold (WinNT; I) Host: hyphotetical.ora.com Accept: image/gif, image/x-xbitmap, */*

21 A resposta do servidor HTTP/ OK Date: Fri, 04 Oct :31:51 GMT Server: Apache/ Content-type: text-html Content-length: 327 Last-modified: Fri, 04 Oct :06:11 GMT... response header body or entity-body

22 Transação HTML Cliente Servidor

23 HTML (Hypertext Markup Language)

24 Transações

25 Método POST POST /cgi-bin/query HTTP/1.0 Referer: Connection: User-Agent: Host: Accept: Content-type: application/x-www-form-urlencoded Content-length: 47 querytype=subject&queryconst=numerical+analysis

26 Tipos de métodos de requisição GET POST

27 Método PUT PUT /example.html HTTP/1.0 Connection: User-Agent: Pragma: Host: Accept: Content-Length: { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com.br/385393/3/slides/slide_26.jpg", "name": "Método PUT PUT /example.html HTTP/1.0 Connection: User-Agent: Pragma: Host: Accept: Content-Length:

28 Estrutura de uma transação HTTP

29 Requisição do Cliente Method URI HTTP-version General-header Request-header Entity-header Entity-body

30 Resposta do Servidor HTTP-version Status-code Reason-phrase General-header Response-header Entity-header Entity-body

31 Estrutura de uma requisição do cliente

32 Estrutura de uma resposta do Servidor

33 Capítulo 3 – Aprendendo HTTP HTTP é um protocolo stateless no qual o cliente faz uma requisição (request) ao servidor que envia uma resposta (response) e então a transação é finalizada

34 Métodos de Requisição do Cliente O método de requisição do cliente é um comando ou uma requisição que o cliente web faz ao servidor Métodos: GET, POST, HEAD, DELETE, TRACE, PUT

35 GET: obtendo um Documento

36 HEAD: Obtendo a informação do cabeçalho

37 POST: Enviando dados ao servidor

38 PUT: Armazenando o Entity- Body na URL

39 DELETE: Removendo a URL

40 TRACE: View the Clients Message Through the Request Chain

41 Versões do HTTP HTTP 1.0 HTTP 1.1 melhor implementação de conexões persistentes Multihoming (permite um único host, porém respondendo por vários domínios diferentes) entity tags byte ranges – permite que apenas partes do documento sejam recuperadas digest authentication

42 Códigos de Resposta do Servidor Faixa de valores Significado da Resposta Informacional Requisição do cliente foi feita com sucesso A requisição do cliente foi redirecionada. Outras alterações são necessárias Requisição do cliente está incompleta Erros do servidor

43 Cabeçalhos HTTP

44 Diferentes tipos de cabeçalhos General headers Request headers Response headers Entity Headers

45 Conexões Persistentes Connection: Keep-Alive

46 Tipos de mídia Accept header Content-Type Exemplos: Accept: */* Accept: type/* Accept: type/subtype

47 Caching de Cliente

48 Obtendo o tamanho do Conteúdo cabeçalho Content-length

49 Faixa de Bytes (Byte ranges)

50 Referring Documents Referer header

51 Identificação de Cliente e Servidor

52 Autorização An Authorization header is used to request restricted documents Authorization: SCHEME REALM Exemplo: Authorization: BASIC username:password, onde username:password é codificado em base64

53 Autenticação The realm of the BASIC authentication schema indicates the type of authentication requested See also Digest authentication (disponível em HTTP 1.1)

54 Cookies Set-Cookie e cabeçalhos Cookie

55 Capítulo 4 – A Biblioteca Socket The socket library is a low-level programmers interface that allows client to set up a TCP/IP connection and communicate directly to servers. Servers use sockets to listen for incoming connections, and clients use sockets to initiate transactions on the port that the server is listening to.

56 Uma conversação típica usando Sockets

57 Socket Calls socket() bind() listen accept() sysread() syswrite() sysread() close() socket() connect() syswrite() close() Rotinas do ClienteRotinas do Servidor

58 Usando chamadas de Socket FunçãoUsoProposta socket() connect() sysread() syswrite() close() bind() listen() accept()

59 Capítulo 5 – A biblioteca LWP A Web trabalha sobre o protocolo TCP/IP, onde o cliente e o servidor estabelecem uma conexão e trocam as informações necessárias através dessa conexão

60 Apêndice A – Cabeçalhos HTTP Há quatro categorias de cabeçalhos: General Request Response Entity

61 Summary if Support Across HTTP Versions HTTP 0.9 HTTP 1.0 HTTP 1.1

62 Apêndice B – Tabelas de Referência Media Types Character Encoding Languages Character Sets

63 Tipos de Mídias Content-type header Accept header Internet Media Types

64 Text Type/Subtype text/plan text/richtext text/enriched text/tab-separetae-values text/html text/sgml

65 Multipart Type/Subtype

66 Message Type/Subtype

67 Application Type/Subtype

68 Codificação de Caracteres Content-type of applicatrion/x-www- form-urlencoded caracteres especiais são codificados para eliminar a ambiguidade Veja RFC 1738 (http://www.faqs.org/rfcs/rfc1738.html)http://www.faqs.org/rfcs/rfc1738.html

69 Linguagens A language tag is of the form of: where zero or more subtags are allowed See RFC 1766 for more information

70 Conjunto de Caracteres Accepted-language Content-language Veja RFC 1700 (http://www.faqs.org/rfcs/rfc1700.html)http://www.faqs.org/rfcs/rfc1700.html

71 Bibliografia WONG, C. Web Client Programming with Perl. 1st Edition March OReilly [2] URL:http://www.w3.org/pub/WWW/Pro tocols/

72 Glossário IANA – Internet Assigned Number Authority CGI – Common Gateway Interface

73 Backup Slides

74 HTTP é stateless O HTTP é um protocolo stateless (sem- estado) não existe uma conexão permanente entre o servidor e o cliente (navegador) portanto o servidor não sabe se uma conexão seguinte está relacionada a conexão anterior

75 Protocolo HTTP Request HTTP (requisição) Response HTTP (resposta) Corpo de uma requisição HTTP

76 Cookies São informações armazenadas no computador do usuário que são opcionalmente enviadas em cada requisição pelo navegador, processado pelo servidor e recebido de volta na resposta

77 Container Web

Carregar ppt "Protocolo HTTP. Let us start with this quote from the HTTP specification document [2]: The HTTP protocol is based on a request /response paradigm. A client."

Apresentações semelhantes

Anúncios Google