angular2 http 請求

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();
    }

}
相關文章
相關標籤/搜索