Angular 2,ASP.NET Core,WebAPI

时间:2017-08-08 12:26:40

标签: asp.net angular http

如何从httpPUT请求获取数据? 控制器:

if (clientBalances.amount > currentAmount.amount)
        {
            return Content("Insufficient funds in your account");
        }

成分:

headers.append('Content-Type', 'application/json');
    this.http.put(this.originUrl + '/api/ClientBalances/Out', JSON.stringify(balance), { headers: headers }).subscribe(result => {
        this.Message = result.json();
    });

但是这只返回“状态为响应:URL为200 OK”。 我怎样才能得到我的信息?

1 个答案:

答案 0 :(得分:0)

您缺少http方法的.map()部分。您还需要从Http, Response

导入'@angular/http';
public method(): void {
    let url: string = this.originUrl + '/api/ClientBalances/Out';
    this.http.put(url, balance)
        .map((res: Response) => res.json())
        .subscribe((result: any) => {
    });
}