1.导入
1
2
3
4
|
import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Http, RequestOptions, Headers, URLSearchParams} from '@angular/http';
import 'rxjs/add/operator/map';
|
2. 代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
clickPost() {
const url = '接口地址';
const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'});
const d1 = new URLSearchParams();
d1.append('param1', 'param1' );
d1.append('param2', ' param2' );
d1.append('param3', 'param3' );
const options = new RequestOptions({ headers: headers });
this.http.post(url, d1, options )
.map(res => res.json())
.subscribe(function (data) {
console.log(data);
});
}
|
参考:https://stackoverflow.com/questions/35212341/angular2-http-post-request-parameters
本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/7340269.html,如需转载请自行联系原作者