Angular 4 http通讯 解决服务器参数无法接收问题
Posted on 2017-08-10 17:08 work hard work smart 阅读(2174) 评论(0) 编辑 收藏 举报1.导入
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); }); }
参考:https://stackoverflow.com/questions/35212341/angular2-http-post-request-parameters
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!