[英]web api, routing issue with my post method
I have an issue with my web api controler routing. 我的Web api控制器路由存在问题。 I've made GET methods that works fine, but now, I try some POST and routing seems to be bad.
我已经使GET方法可以正常工作,但是现在,我尝试了一些POST,并且路由似乎很糟糕。 I've have a front and with Angular2.
我有一个前台,并且在Angular2上有。 Here, you can see the call to webapi :
在这里,您可以看到对webapi的调用:
retour = this._http.post("http://localhost:5000/api/Particulier/add", _particulier, options)
.map(postResult)
.catch(this.handleError);
Here it's my web api method : 这是我的网络api方法:
[Route("api/[controller]/")]
public class ParticulierController : Controller
{
[...]
[HttpPost("add")]
public async Task<bool> Add([FromBody]Particulier particulier)
{
var result = await _particulierService.Create(particulier);
return result;
}
[...]
}
it's simple, but doesn't work. 很简单,但是不起作用。 Chrome say me that the url doesn't exist.
Chrome告诉我该网址不存在。 I have GET methods in the same controller and they works.
我在同一控制器中有GET方法,并且它们可以工作。
can you help me ? 你能帮助我吗 ?
thanks, 谢谢,
The method Add([FromBody]Particulier particulier)
may not be matching your request because there are missing non-nullable properties specified for the Particulier
parameter. 方法
Add([FromBody]Particulier particulier)
可能与您的请求不匹配,因为缺少为Particulier
参数指定的不可为空的属性。 Or, it could be an issue with deserializing the request. 或者,反序列化请求可能是一个问题。
I recommend trying it with the Content-Type: text/json
header if it's not an issue with missing properties. 如果不是缺少属性的问题,我建议您尝试使用
Content-Type: text/json
标头。
retour = this._http({
url: 'http://localhost:5000/api/Particulier/add',
method: "POST",
data: _particulier,
headers: {'Content-Type': 'text/json'}
}).success(function(data, status, headers, config) {
// map post result (data var)
});
Ok, it's resolved. 好,解决了。 The request is not executed until the Angular service is not subsribed.
直到不提供Angular服务,请求才会执行。
thanks to everyone 谢谢大家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.