简体   繁体   English

net :: ERR_CONNECTION_RESET 200(确定),当执行GET方法时

[英]net::ERR_CONNECTION_RESET 200 (OK) when doing GET method

I changed my Apartments Model Class by adding a BuyerID which is a foreign key to another Buyer Class like this: 我通过向另一个买方类添加外键BuyerID来更改了我的公寓模型类,如下所示:

public class Apartment
    {
        [Key]
        public int ID { get; set; }
        public string Title { get; set; }
        public int NbofRooms { get; set; }
        public int Price { get; set; }
        public string Address { get; set; }
        public int BuyerId { get; set; } 

    }

Also I have my Buyers Model Class as the following: 我还有以下的“买方模型”类:

public class Buyer
    {
        [Key]
        public int ID { get; set; }
        public string FullName { get; set; }
        public int Credit { get; set; }
        public ICollection<Apartment> apartments { get; set; }
    }

So it also contains a collection of Apartments. 因此它也包含公寓的集合。 and because of this maybe my Get method isn't working anymore and is returning the following error: GET http://localhost:54632/api/Apartments net::ERR_CONNECTION_RESET 200 (OK) 并且由于这个原因,我的Get方法可能不再起作用,并返回以下错误:GET http:// localhost:54632 / api / Apartments net :: ERR_CONNECTION_RESET 200(确定)

The only GET Method not working is this one: 唯一无法使用的GET方法是以下方法:

// GET: api/Apartments
        [HttpGet]
        public IEnumerable<Apartment> GetApartments()
        {
            return _context.Apartments;
        }

Otherwise the others such as this: 否则其他如下:

// GET: api/Apartments/5
        [HttpGet("{id}")]
        public async Task<IActionResult> GetApartment([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var apartment = await _context.Apartments.SingleOrDefaultAsync(m => m.ID == id);

            if (apartment == null)
            {
                return NotFound();
            }

            return Ok(apartment);
        }

is working fine.Also if I try the link on chrome it returns the apartments but if I try it on Postman or Angular App it returns the error. 工作正常。如果我在chrome上尝试链接,它将返回公寓,但是如果在Postman或Angular App上尝试,它将返回错误。 What could be the cause of this error? 造成此错误的原因是什么? Thank you. 谢谢。

I had the same problem, and it was due to having created a self-referencing loop in the data I was trying to serialize. 我遇到了同样的问题,这是由于在我要序列化的数据中创建了一个自引用循环。 Looking at the recent change you had made it looks like you also created an object tree with a self referencing loop by referencing back to a Buyer from Apartments. 查看最近所做的更改,就好像您还通过从Apartments引用回购者来创建带有自引用循环的对象树一样。

Json.Net gets upset by this and gives up. Json.Net对此感到沮丧并放弃了。 I would expect an exception to be thrown as in this question , but I didn't get one, I had the same symptoms as you describe. 我希望会像在此问题中一样引发异常,但是我没有得到一个异常,我有与您描述的症状相同的症状。

If you are having the same root problem, it is solved by setting JSON.Net to detect and ignore self referencing loops during startup configuration as explained here or here for asp.net core . 如果您遇到相同的根本问题,可以通过将JSON.Net设置为在启动配置过程中检测和忽略自引用循环来解决,如此此处对asp.net core所述

Asp.Net: Asp.Net:

HttpConfiguration config = GlobalConfiguration.Configuration;

config.Formatters.JsonFormatter
            .SerializerSettings
            .ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

Asp.net Core: Asp.net核心:

services.AddMvc().AddJsonOptions(options =>
{
    options.SerializerSettings.ReferenceLoopHandling = 
                               Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});

open chrome then open DevTools by pressing F12 and navigate to network tab. 打开chrome,然后按F12打开DevTools并导航至“网络”标签。 Find your API request and select copy > copy as cURL 找到您的API请求,然后选择复制>复制为cURL

now you can compare curl request and postman request in order to see difference. 现在,您可以比较curl请求和邮递员请求以查看差异。 The difference will give you the problem. 差异会给您带来问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 得到 <URL> 网:: ERR_CONNECTION_RESET - GET <URL> net::ERR_CONNECTION_RESET 错误101(net :: ERR_CONNECTION_RESET):连接已重置 - Error 101 (net::ERR_CONNECTION_RESET): The connection was reset 从C#Web API方法下载ZipArchive在Chrome中返回“ net :: ERR_CONNECTION_RESET” - Download ZipArchive from c# web api method returns “net::ERR_CONNECTION_RESET” in chrome 尝试访问ASP.NET Web App项目上的localhost时出现ERR_CONNECTION_RESET - ERR_CONNECTION_RESET when trying to access localhost on ASP.NET Web App project JavaScript获取请求错误:无法加载资源:net :: ERR_CONNECTION_RESET - JavaScript get request error: Failed to load resource: net::ERR_CONNECTION_RESET ASP.NET 4.6-ERR_CONNECTION_RESET - Asp.net 4.6 - ERR_CONNECTION_RESET 调试 jquery 数据表服务器端:ERR_CONNECTION_RESET 200 错误 - debug the jquery dataTable server side :ERR_CONNECTION_RESET 200 error 通过POST服务在C#异步方法中调用Edge.func时出现ERR_CONNECTION_RESET错误 - ERR_CONNECTION_RESET error when calling Edge.func in C# async method through POST service 对 ASP.NET MVC 控制器的 Ajax POST 调用给出 net::ERR_CONNECTION_RESET - Ajax POST call to ASP.NET MVC controller giving net::ERR_CONNECTION_RESET IIS Localhost Asp Net MVC应用程序抛出Erro 101(net :: ERR_CONNECTION_RESET) - IIS Localhost Asp Net MVC application trows Erro 101 (net::ERR_CONNECTION_RESET)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM