Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net web api HttpPost到web api始终是空参数_Asp.net Web Api_Angular_Asp.net Core - Fatal编程技术网

Asp.net web api HttpPost到web api始终是空参数

Asp.net web api HttpPost到web api始终是空参数,asp.net-web-api,angular,asp.net-core,Asp.net Web Api,Angular,Asp.net Core,我正在尝试从angular 2应用程序向web api应用程序发布一些数据。它只是一个小的json字符串,当我点击WebAPI控制器时,该项总是空的——无论我尝试了什么 json是(我可以从警告数据中看到这一点) 角函数是 createUser(user: Profile): Observable<Response> { let url = this.usersUrl; let data = JSON.stringify(user); let hea

我正在尝试从angular 2应用程序向web api应用程序发布一些数据。它只是一个小的json字符串,当我点击WebAPI控制器时,该项总是空的——无论我尝试了什么

json是(我可以从警告数据中看到这一点)

角函数是

    createUser(user: Profile): Observable<Response> {

    let url = this.usersUrl;
    let data = JSON.stringify(user);
    let headers = new Headers({'Content-Type': 'application/json; charset=utf-8' });
    let options = new RequestOptions({ headers: headers });

    return this.http.post(url, data, options);
}
但是,当我在Create中断点时,User项为null

我试过:

   public IActionResult Create([FromBody] User item)
但是Chrome控制台窗口中的错误消息是

Failed to load resource: the server responded with a status of 415 (Unsupported Media Type) 
我试过了

    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' });
但误差与上述相同


有什么想法吗?:)

我想你的问题是API中的用户模型。属性必须完全相等。

使用
JSON.parse()
而不是
JSON.stringify()
在这里让data=JSON.stringify(用户);如果你有json字符串,不要使用任何东西,只要让data=user;无法工作。用户是具有firstname、lastname属性的类。错误消息-将不编译类型配置文件不可分配给字符串类型的参数。请为CONTORLER方法public IHttpActionResult Create(JObject user)ha尝试此签名。sado记下了什么?
Failed to load resource: the server responded with a status of 415 (Unsupported Media Type) 
    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' });