Axios在POST上引发网络错误

时间:2018-07-19 12:41:01

标签: asp.net asp.net-web-api axios

使用axios发布到ASP.NET WEB API控制器。下面是代码。我可以打电话给“ get”,但是当我发表文章时,我遇到了网络错误。

enter image description here

如果我将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);
        }

0 个答案:

没有答案
相关问题