ajax 报错400,ajax 调用 .net core WebAPI,报错 400 (Bad Request) Unexpected character encountered while pars...

400 (Bad Request) Unexpected character encountered while parsing value

情况说明

基于 .net core 写了一个 Web API,用 postman 测试时,能够 POST 返回数据,但是用 ajax 调用 API 时就会报错(400)。

前端 ajax 调用报错

eb7e106b8e9fb52285a30470dcfb71ad.png

postman 调用正常

384db3a50cade8be27d41aaf189e785d.png

服务端相关代码

[HttpPost]

public async Task>> PostFlow([FromBody] PostParams data) // dynamic

{

return await _context.Set().Where(s => data.Czid.Contains(s.Czid) && s.Rq >= data.Begin && s.Rq <= data.End).ToListAsync();

}

public class PostParams

{

public DateTime Begin { get; set; }

public DateTime End { get; set; }

public int[] Czid { get; set; }

}

前端ajax

$.ajax({

type: "POST",

url: "http://localhost/rfapi/api/flow",

data: {"czid": ["1"], "begin": "2017-03-30 00:00:00", "end": "2017-03-31 00:00:00"},

contentType: "application/json",

async: true,

dataType: "json",

success: function(data) {

console.log(data.length);

},

error: function(err) {

console.log(err);

}

});

不好意思,分数不够了。。

4e7399d45f7c094d2865984ee89b3a2e.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值