ionic Http请求模块主要基于Angularjs 下两个模块:
1.{Http}from'@angular/http';
2.{HttpClient,HttpClientModule}from'@angular/common/http';
目前个人的Ionic版本号为3.19,在使用Http 模块1的时候,提示已经废弃,就选择了使用模块2HttpClient。
HTTP的POST提交的四种常见消息主体格式:
1.application/x-www-form-urlencoded
普通的表单提交
2.multipart/form-data
数据提交,一般用于文件上传
3.application/json
json数据格式
4.text/xml
xml数据格式
AngularJS 的POST请求几种设置:
1.纯body形式,实体方式传入
请求代码

请求信息


所以得出AngularJS 的POST请求,使用body, 默认Content-Type是”application/json”,并不是表单形式的”application/x-www-form-urlencoded”提交,服务端接收到的是对象,而不是字段。
2.HttpParams +表单设置 方式提交数据
请求代码

请求信息


所以得出HttpParams请求方式,将参数加入到请求地址中,类似于Get请求,此时不存在表单数据。
3.body+表单设置方式
请求代码

请求信息


通过三种方式请求可以知道,Angularjs Http post方式请求中,HttpParams 主要用于在Http请求地址后追加请求参数;表单或者json提交方式的设置对其都没有任何影响。表单或者json方式设置,可以影响到Body数据的格式。
网友评论