【发布时间】:2018-11-22 16:50:31
【问题描述】:
我尝试从 axios 对 asp.net core 2.1 webapi 进行 get api 调用
webapi 控制器
[Route("api/[controller]")]
[ApiController]
[HttpsRequirement(SslRequirement.Yes)]
public class GHTKController : ControllerBase
{
[HttpGet("GetShippingFee")]
[Produces("application/json")]
public async Task<IActionResult> GetShippingFee([FromBody]GhtkAddress address)
{
return Ok();
}
}
它通过了带有 json(application/json) body 的 Postman 测试
{ "pick_province":"asda" }
但是它无法从带有 VueJs 的 axios 运行并返回状态 400
import axios from 'axios'
export default {
async getShippingFee(address) {
console.log(address)
const request = await axios.get('/api/ghtk/getshippingfee', {
pick_province: "asda"
})
.then(response => response)
.catch(error => {
console.log(error)
});
return request;
},
}
【问题讨论】:
标签: asp.net-web-api vue.js asp.net-core axios