【发布时间】:2018-08-22 17:09:29
【问题描述】:
我将 http post 方法从 angular4 组件调用到 web api。当我在控制台上打印从 web api 返回的这些值时,它会打印空值。我也使用邮递员检查了请求。它也没有工作。
来自组件文件的 Http post 调用。
EditValue(event, name, id) {
const headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
const options = new RequestOptions({ headers: headers });
let body = { "name" : name, "id": id }
this.http_.post('http://localhost:12412/api/employee?', body, options)
.subscribe((data) => {console.log(data)});
}
web api 中的 Http post 方法。
[HttpPost]
public string postemp(Model model)
{
return "name:" +model.name + " , " + "id: " + model.id;
}
public class Model
{
public int id { get; set; }
public string name { get; set; }
}
当我从 Editvalue 函数中检查名称和 ID 时,这些值正在传递。我也尝试了Angular4 http post method does not pass data to web api 给出的解决方案。但问题没有解决。如何检查那些发布的数据是否传递给 web api post 方法?
我附上了下面得到的响应结果。
【问题讨论】:
-
你能改变内容类型吗? ..,你试过了吗?
-
你在用HttpClient吗?
-
没有。我用的是Http。
-
您是否检查了 EditValue 函数上的传入参数值?您可以尝试将它们登录到您的控制台吗?
-
@E.L.N.D.Madubhashini 您的问题与Angular4 http post method does not pass data to web api 中的问题不同吗?
标签: html angular typescript asp.net-web-api