c# - Angular 6中的发布方法不发送数据
问题描述
当我使用 get 进行 api 调用时,当我转换为发布它在参数中给我空值时,它工作得很好。我必须使用 [FromBody] 然后只调用 api 但仍然给我参数值 null。我也处理过CORS。
const httpOptions = {
headers: new HttpHeaders({
'Content':"application/json",
'Content-Type': 'application/json;charset=utf-8',
//'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Authorization': 'Basic ' + btoa(Username + ":" + Password),
}),
};
checkLogin(form){
var obj = { Business_Email: form["Business_Email"], Business_Password: form["Business_Password"] };
return this.http.post(this.API_URL+"/Login/LoginValid", JSON.stringify(obj),httpOptions)
}
我在 Asp .net C# 中有 Web Api
[HttpPost]
[ActionName("LoginValid")]
[Route("api/Login/LoginValid")]
public ReturnObject LoginValid([FromBody]string businessMaster)
{
//Code
}
解决方案
我有类似的代码可以在 angular 6 上正常工作。
addEmployee(emp: Employee): Observable<number> {
return this.http.post(this._baseURL + "/api/employee", emp).pipe(
map(success => success.status))
}
[HttpPost]
public void Post([FromBody]Employee employee)
{
db.Employees.Add(employee);
db.SaveChanges();
}
推荐阅读
- javascript - 扩展数组 Javascript
- lotus-notes - XML 导出“20151222T081838,00-05”中的 Lotus Notes 日期
- html - Razor 页面日期时间输入错误大小
- c++ - 如何声明一个 C++ 变量应该被改变
- css - 添加前置时,BootStrap 选择的宽度错误
- namespaces - 带有变量变量的命名空间
- r - 在 ggplot2 的 geom_point 中使用 reorder 函数
- reactjs - 使用“npm run build”后图像未加载
- sdk - Dynamics CRM OrderBy 表达式不起作用
- wordpress - 徽标将无法在实际移动设备上正确显示 [但在更改桌面屏幕尺寸时会显示]