Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我在React应用程序中的获取URL没有更改?_C#_Ajax_Reactjs_Asp.net Core Mvc_Fetch - Fatal编程技术网

C# 为什么我在React应用程序中的获取URL没有更改?

C# 为什么我在React应用程序中的获取URL没有更改?,c#,ajax,reactjs,asp.net-core-mvc,fetch,C#,Ajax,Reactjs,Asp.net Core Mvc,Fetch,我有一些奇怪的事情,我正试图解决。我的目标是在Fetch调用中使用AntiForgeryToken。从昨天起我就一直在做这件事,但我面临着一个麻烦 在我的React应用程序中,我有一个获取调用: fetch('/comments/new?', { method: 'POST', body: JSON.stringify({ data })

我有一些奇怪的事情,我正试图解决。我的目标是在Fetch调用中使用
AntiForgeryToken
。从昨天起我就一直在做这件事,但我面临着一个麻烦

在我的
React
应用程序中,我有一个获取调用:

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

但是,如果我将Fetch URL更改为
Fetch('/comments/new/dupa?'),
和构造函数将URL路由到我的XHR日志中的
[Route(“comments/new/dupa”)]
,Fetch调用也是一样的(!):
http://localhost:58256/comments/new?Name=aaa&Change=aa&Opinion=good

另一件奇怪的事情是,XHR日志将调用识别为
GET


我不明白为什么。我非常感谢任何帮助。

这是我愚蠢的错误。因为我有几个月没有在React中编写代码,我只是忘记了在保存更改时使用
npm start
构建应用程序