3.Android network programming presentation -http

1.HTTP request method

The standard HTTP, HTTP request can use several request methods.

HTTP1.0 request defines three methods: GET (check), the POST (change) and the HEAD (Get header, typically used to test whether the link normally) method.

HTTP1.1 five new request method: Put (increase), Delete (delete), OPTIONS (see server performance), TRACE (retroactive server requests received before, used to find problems) and other methods.

No.

method

description

1

GET

Request page information specified, and returns the entity body.

2

HEAD

Similar to the GET request, returns a response but not the specific content, for obtaining the header

3

POST

Submitting data to the processing request specified resource (e.g., file submission form or upload). Data contained in the request body. POST request may result in a revision to establish and / or existing resources to new resources.

4

PUT

Data transmitted from the client to the server designated to replace the contents of the document.

5

DELETE

Requests the server to delete the specified page.

6

CONNECT

HTTP / 1.1 protocol can be reserved for connection to the proxy server pipeline mode.

7

OPTIONS

It allows the client to view server performance.

8

TRACE

Echo request received by the server, mainly for testing or diagnosis.

9

PATCH

It complements the PUT method, used locally known resource update.

 

And HTTP1.0 provisions browser and server to maintain only brief connection, will be disconnected after each request, a request that contains multiple page documents and answer the many images you need to connect several times to complete the transfer.

The HTTP1.1 supports persistent connections, reducing the consumption of establishing and closing connections and delays, one containing a plurality of requests and responses many pages of image files can be transmitted in a connection.

 

2.get and post

  • get:   time to get all the parameters will be submitted to fight in the back url to access and accept only less than 1k, & each parameter separated due to the parameter content is displayed, it can only apply to non-access privacy. .
  • post:  When all the parameters sucked post requested contents key = value form into the request body, and the length is not limited.

3.request request

The client request contains four parts:

  • Request line (request line) 
  • Request header (header) 
  • Blank line,
  • Request body 

To get an example:

 

  • Host: tell the server, the client's address
  • User-Agent: client type, represented here by a windows computer, using QQBrowser browser (if it is the phone, the phone will display specific types)
  • Accept: tell the server can support the type of data processing
  • Accept-Lanauage:  tell the server that can support the language
  • Accept-Encoding:   tells the server, the data format which can support decompression
  • Referer:  tell the server from which the page is a link to a page over
  • Connection:  state of the connection, represented here remain connected

 

And to post the words:

  

More than two request header:

  • Content-Type: application / x-  www-form-urlencoded: request url encoded body
  • : Content-Length: 41 length of the request submitted by the body

Request body exactly 41 bytes:

yuwen1=12&shuxue1=23&yuwen2=34&shuxue2=55

 

 

4.response 响应

客户端请求包含了4个部分:

  • 响应行(包含响应码)、
  • 响应头、
  • 空行、
  • 响应体

常见的响应码有:

  • 200~299 : 请求成功,服务器成功返回数据,比如200(get/post请求成功)
  • 300~399 : 服务端收到了请求 但是需要客户端作进一步操作,比如304(告诉客户端使用缓存)
  • 400~499 : 请求错误(客户端问题),比如404(资源不存在)
  • 500~599 :内部服务器错误,比如500(服务器内部错误) 

示例如下:

 

  • Server : 描述服务器端类型
  • Accept-Ranges : 表示当前返回的数据单位
  • Last-Modified :  表示请求的资源的最后被修改的时间,这个字段的作用就是用于缓存服务器机制,用于判断缓存服务器中的资源是否过期,是否需要从源服务器更新。
  • ETag : 表示请求资源的版本,如果该资源发生变化,那么这个属性也会跟着变,和Last-Modified一样,可以用来判断缓存中的资源是否过期
  • Content-Type : 响应的类型
  • Content-Length : 响应体的数据长度
  • Date : 数据响应的时间

 

 未完待续,下章学习servlet~

Guess you like

Origin www.cnblogs.com/lifexy/p/12275202.html