仅在IE11上使用参数调用控制器时,Stream意外结束

时间:2018-09-24 11:22:56

标签: asp.net-core axios asp.net-core-2.0

我的VueJS SPA中遇到了最奇怪的问题。

当使用需要GET参数的axios调用我的控制器方法时,IE11总是以500个响应结尾。

但是当以完全相同的方式调用它时,使用与Chrome或Firefox相同的代码,就没有问题。

另一个奇怪的事情是,当我删除参数要求并硬编码id时,它可以正常工作。

我的控制器方法:

[HttpGet]
public IActionResult _method(int id)
{
  var data = methodsThatReturnsData(id);
  return JsonDataResponse(data);
}

asp.net的完整错误

IOException: Unexpected end of Stream, the content may have already been read by another component.
    Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

1 个答案:

答案 0 :(得分:0)

找到了罪魁祸首!

显然,当您在GET调用中添加数据选项时,IE11不喜欢它。

它将content-type添加到标题中,其他浏览器则不添加,而ASP.net不喜欢

示例:

axios({
  method: options.type,
  url: options.url,
  headers: {
    'X-Requested-With': 'XMLHttpRequest'
  },
  data: options.data, <-- Works when removing this for get calls
  params: options.params
})