接口文档API、剖析http协议, 原生http请求函数
http协议:超广本传输协议
特点:
短连接 请求完成后就断开
无状态 对于事务处理无记忆能力
媒体独立 客户端要指定适合的传输内容类型,如json
http 是建立在tcp/ip协议之上的应用层协议
H5新增的: 长连接 websocket 双向通信
http主要三部分: 请求行(url),请求头(header),请求体(参数)响应头
http 1.0: get post
http 1.1 : put delete options
restful api 风格 (细化)
get—查询,post --添加, put--修改, delete -- 删除
get:获取数据
post: 添加 修改 删除
差别:get的参数拼接在url后面,(http://www.xx.com/?name=xxx&age=20 或者 http://www.xx.com/:name)参数有长度限制
post参数在请求体,请求体参数:json ,formdata
与put,delete没有差别,名字风格不同
options --试探跨域
跨域:
地址:协议 IP 端口
http请求:
function getXMLHttpRequest(){
var xmlhttp;
if(window.ActiveXObject){
// ie5 ie6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
// ie7+ ff chrome 浏览器原生
xmlhttp = new XMLHttpRequest();
}else {
xmlhttp = null;
}
return xmlhttp
}
function getData(){
var xmlhttp = getXMLHttpRequest();
// true异步 false同步
xmlhttp.open(‘get‘,‘http://localhost:3000/info‘,true);
xmlhttp.send();//发送请求
xmlhttp.onreadystatechange = function(){
//200 请求成功
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
console.log(xmlhttp.responseText);
}
}
} 相关推荐
hygbuaa 2020-11-22
坚持着执着 2020-07-16
zhaolisha 2020-06-16
坚持着执着 2020-06-14
李永毅 2020-05-29
malachuan 2020-05-17
Richardxx 2020-05-16
87510793 2020-05-09
用不完的好奇心 2020-05-08
hygbuaa 2020-02-20
zhaolisha 2020-01-12
wanghongsha 2019-12-15
83447400 2019-09-17
86520093 2019-11-18
89401052 2014-06-25
heimeiyingwang 2015-03-19