使用axios发布到ASP.NET WEB API控制器。下面是代码。我可以打电话给“ get”,但是当我发表文章时,我遇到了网络错误。
如果我将Content-Type更改为“ x-www-form-urlencoded ”,我可以拨打电话,但发布的json数据不会发布。请同时找到WEB API代码
const defReqConfig = Axios.defaults;
defReqConfig.method = "post";
defReqConfig.baseURL = "http://localhost:16755/api/v1/";
defReqConfig.headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}
const axiosServiceInstance: AxiosInstance = Axios.create(defReqConfig);
return axiosServiceInstance.post("author/pd", postData)
c#Web api代码
[Route("pd")]
[HttpPost]
public HttpResponseMessage Post([FromBody] Author pq)
{
return Request.CreateResponse(HttpStatusCode.OK, pq);
}