【Android】Http基础

http是什么?

直观印象

  1、浏览器输入网址,打开网页
  2、Android中发送网络请求,返回对应内容
  HyperText Transfer Protocol 超文本传输协议
  html 存储和表达文本的格式

http的工作方式

直观:

  在浏览器地址栏输入网址,点击回车向服务器发送请求,服务器接受请求返回结果,浏览器接收结果通过浏览器内核渲染到屏幕。

url如何转化为报文

示例:

http://hencoder.com/users?gender=male

协议类型:http:
服务器地址://hencoder.com
路径:/users?gender=male

请求 报文
GET //users?gender=male HTTP/1.1
Host:hencoder.com

报文格式 Request 由请求行、Headers、Body组成

请求行:
method: GET
path: /users
HTTP version: HTTP/1.1

Headers:
Host:hencoder.com
Content-Type: test/plain
Content-Length: 243

Body:
不是必须的

报文格式 Response 由状态行、Headers、Body组成

状态行:
HTTP version:HTTP/1.1
status code: 200
status message: OK

Headers:
content-type:application/json; charset=utf-8
cache-control:public,max-age=60,s-message=60

Body:
[json]

你可能感兴趣的:(【Android】Http基础)