angular2 http 请求
发布时间:2020-12-17 09:42:40 所属栏目:安全 来源:网络整理
导读:export class MsgTestComponent implements OnInit { data: any; constructor(private http: Http) {} ngOnInit() { } postTest() {//参数传递,放到body里 var reqJson = {name: "1234",upstream_url: "http://192.168.1.45:33890",request_host: "1234.com
export class MsgTestComponent implements OnInit { data: any; constructor(private http: Http) {} ngOnInit() { } postTest() { //参数传递,放到body里 var reqJson = {name: "1234",upstream_url: "http://192.168.1.45:33890",request_host: "1234.com"}; this.http.post("http://192.168.1.46:8001/apis",reqJson) .map(resp => { console.log(resp); this.data = resp.json(); }) .subscribe(); } getTest() { //get方式不用传参 this.http.get("http://192.168.1.46:8001/apis") .map(res => { console.log(res); this.data = res.json() }) .subscribe(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |