POST data from Android to Web API returns 404

本秂侑毒 提交于 2019-11-30 17:04:49

I fixed this by properly setting up my backend to accept the parameters sent by the android client. The problem was with my backend, not my client.

Here's my backend:

[Route("api/postcomment")]
public IHttpActionResult PostComment([FromBody] CommentViewModel model)
{
       string comment = model.Comment;
       //Do your processing
       return Ok(return_something);
}

public class CommentViewModel
{
        public string Comment { get; set; }
        public string Email { get; set; }
        public string Actid { get; set; }
}

I used the [FromBody] to force the method to read the request body and I used a model to get the values passed by the client. The method automatically gets the values from the request and sets them to the model making it very easy.

MAKE SURE that your android client is properly passing your parameters with a correct POST code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!