c# - 为什么我在 React 应用程序中的 Fetch URL 没有改变?
问题描述
我有一些奇怪的东西,我正在尝试解决问题。我的目标是AntiForgeryToken
在我的 Fetch 调用中。我从昨天开始一直在努力,但我遇到了麻烦。
在我的React
应用程序中,我有一个 Fetch 调用:
fetch('/comments/new?',
{
method: 'POST',
body: JSON.stringify({ data }), // data can be `string` or {object}!
headers: { 'Content-Type': 'application/json' },
contentType: "application/json; charset=utf-8",
credentials: 'include'
}
)
.then(res => res.json())
.then(res => {
console.log(res);
})
.catch(error => {
console.error(error);
});
我的SurveyController.cs
样子:
[Route("comments/new")]
public ActionResult AddComment(Survey survey)
{
if (survey == null)
{
return BadRequest();
}
survey.Time = DateTime.Now;
_context.Surveys.Add(survey);
_context.SaveChanges();
return Ok();
}
它可以工作,并且在 XHR 日志获取调用的 URL 中我有:http://localhost:58256/comments/new?Name=aaa&Change=aa&Opinion=good
但是,如果我在我的 XHR 日志中将 Fetch URL 更改为fetch('/comments/new/dupa?',
和构造函数 Route URl 到[Route("comments/new/dupa")]
,则获取调用再次相同(!):http://localhost:58256/comments/new?Name=aaa&Change=aa&Opinion=good
另一个奇怪的事情是GET
XHR 日志将呼叫识别为。
我不懂为什么。我很感激任何帮助。
解决方案
这是我愚蠢的错误。因为我已经有几个月没有在 React 中编码了,而且我只是忘记了在npm start
我保存更改的任何时候构建应用程序。
推荐阅读
- python - Python 中的累积持续时间构建
- c - 在 K&R C 中传递字符串文字
- google-app-engine - Google Cloud Endpoints 和 Guice 出现错误“调用者没有权限”
- requirejs - RequireJS 转译插件应该如何返回结果?
- javascript - 如何根据他们的选择(使用 Mailchimp)将潜在客户发送到特定的邮件列表?
- python - Matplotlib:向散点图添加颜色图例
- python - 如何使用 PyPDF2 在 Python 3 中将 PDF 中的所有页面作为单个字符串检索
- node.js - forEach 不在 lambda 函数内运行
- java - Kafka Connect 无法将自定义存储接收器分区器转换为分区器接口
- java - 找不到接口类型的 Bean