angular2 http post请求
来源:互联网 发布:程序员职业规划之道pdf 编辑:程序博客网 时间:2024/06/05 17:56
import { Http } from ‘@angular/http’;
import { Headers, RequestOptions, URLSearchParams } from ‘@angular/http’;
首先要import 这几个模块,
分别是http请求体,http请求头部,请求options,和请求发送的data,
import { Http } from '@angular/http';import { Headers, RequestOptions, URLSearchParams } from '@angular/http';import 'rxjs/add/operator/toPromise';constructor(private http: Http) { this.headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }); this.options = new RequestOptions({ headers: this.headers }); } private handleError(error: any): Promise<any> { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error); } public getImg(): Promise<object> { const data = new URLSearchParams(); const bodyData = { 'UUID': 'nullfy6HS' }; data.append('body', JSON.stringify(bodyData)); data.append('tradeCode', '0002'); data.append('tradeType', 'authService'); return this.http.post(this.baseUrl, data, this.options) .toPromise().then(response => response.json()).catch(this.handleError); }
返回一个promise函数体
阅读全文
0 0
- angular2 http post请求
- angular2 Http请求
- angular2/angular4 如何通过$http的post方法请求下载二进制的Excel文件
- angular2-英雄指南教程http请求
- angular2实现统一的http请求头
- android http post请求
- http的post请求
- C# http post请求
- HTTP 模拟post请求
- http post get 请求
- http请求post
- ios HTTP post请求
- HTTP GET/POST 请求
- http post get请求
- http post 客户端请求
- HTTP POST 网络请求
- http 原生post 请求
- http post请求
- || &&
- 8.15 C
- 手中无框架,心中有框架
- HashMap/ArrayMap
- Game of Sum UVA
- angular2 http post请求
- 接上一篇
- 1070. 结绳
- 本地jdk版本问题,没走java_home
- IDEA 2017 use JAVA_HOME(not defined yet)
- progeCAD 正版购买 中国 官方授权 代理商 经销商 网络版 专业版 公司授权
- 卓有成效的管理者(笔记)——要事优先
- OGG配置文件——MANAGER
- 错误记录-数据库、SQL,Mybatis的XML