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. 代码
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);
});
}