我正在构建一个以 .Net Core API 作为后端的 Angular 网站。当我发布新的邮政编码时,我的 Angular 服务会正确发送数据,但我的 API 没有接收到数据。
编辑(放置)使用类似的代码可以正常工作。
添加(post):Code 中postcode值为null ,Request Payload中填充postcodes值
编辑(认沽):邮编值不为空的代码,看跌期权的请求负载
邮政编码控制器:
[Route("api/[controller]")]
public class PostcodeController : Controller
{
IPostCodeAcces<PostcodeVerwerking, int> _postcodeRepo;
public PostcodeController(IPostCodeAcces<PostcodeVerwerking, int>p)
{
_postcodeRepo = p;
}
[HttpPost]
public IActionResult Post([FromForm]PostcodeVerwerking postcode)
{
int res = _postcodeRepo.AddPostcode(postcode);
if (res != 0)
{
return Ok();
}
return Forbid();
}
[HttpPut("{id}")]
public IActionResult Put(int id, [FromForm] PostcodeVerwerking p)
{
if (id == p.Id)
{
int res = _postcodeRepo.UpdatePostcode(id, p);
if (res != 0)
{
return Ok(res);
}
return NotFound();
}
return NotFound();
}
}
角度服务:
putPostcode(id, formdata: FormData): Observable<PostcodeVerwerking>{
return this.http.put<PostcodeVerwerking>(this.apiUrl + "/" + id, formdata);
}
postPostcode(formdata: FormData): Observable<PostcodeVerwerking>{
return this.http.post<PostcodeVerwerking>(this.apiUrl, formdata);
}
万千封印
慕沐林林
相关分类