IIS & Chrome: failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

后端 未结 6 1682
感情败类
感情败类 2020-12-06 00:27

I recently came across a Chrome issue which I think is worth sharing it with you.

I worked on a self written API using an HttpHandler which primary should return jso

相关标签:
6条回答
  • 2020-12-06 00:33

    I was also getting same error. This issue was with web server user permission on cache folder.

    0 讨论(0)
  • 2020-12-06 00:34

    In my case, the problem was cache-related and was happening when doing a CORS request.

    Forcing the response header Cache-Control to no-cache resolved my issue:

    [ using Symfony HttpFoundation component ]

    <?php
    $response->headers->add(array(
       'Cache-Control' => 'no-cache'
    ));
    
    0 讨论(0)
  • 2020-12-06 00:34

    On the offchance that someone is landing here as a result of issues with their ASP.net Core project, I was able to resolve by adding the IIS middleware.

    This is done by adding UseIISIntegration when instantiating your webhost instance.

    0 讨论(0)
  • 2020-12-06 00:35

    Once I had the same problem and the main reason was lying in my controller return type. If you try to return a C# object just as-is, you will only get net::ERR_INCOMPLETE_CHUNKED_ENCODING so don't forget to serialize your complex objects before sending them out for java script client (or View). i.e. my controller return type was :

    public async Task<List<ComplexModel>> GetComplexModelList(){
        return new List<ComplexModel>()
    }
    

    Which caused INCOMPLETE_CHUNKED_ENCODING error, so I tried to fix my mistake with something like:

    using Newtonsoft.Json;
    ...
    public async Task<string> GetComplexModelList(){
        return JsonConvert.SerializeObject(new List<ComplexModel>())
    }
    
    0 讨论(0)
  • 2020-12-06 00:46

    I was running into this error when generating a file and pushing it to the user for download, but only occasionally. When it didn't fail, the file was consistently 2 bytes short. Close() forcibly closes the connection, whether it's finished or not, and in my case it was not. Leaving it out, as suggested in the question, meant the resulting file contained both the generated content as well as the HTML for the entire page.

    The solution here was replacing

    context.Response.Flush();
    context.Response.Close();
    

    with

    context.Response.End();
    

    which does the same, but without cutting the transaction short.

    0 讨论(0)
  • 2020-12-06 00:50

    According to ASP.NET sets the transfer encoding as chunked on premature flushing the Response:

    ASP.NET transfers the data to the client in chunked encoding (Transfer-Encoding: chunked), if you prematurely flush the Response stream for the Http request and the Content-Length header for the Response is not explicitly set by you.

    Solution: You need to explicitly set the Content-Length header for the Response to prevent ASP.NET from chunking the response on flushing.

    Here's the C# code that I used for preventing ASP.NET from chunking the response by setting the required header:

    protected void writeJsonData (string s) {
        HttpContext context=this.Context;
        HttpResponse response=context.Response;
        context.Response.ContentType = "text/json";
        byte[] b = response.ContentEncoding.GetBytes(s);
    
        response.AddHeader("Content-Length", b.Length.ToString());
    
        response.BinaryWrite(b);
        try
        {
            this.Context.Response.Flush();
            this.Context.Response.Close();
        }
        catch (Exception) { }
    }
    
    0 讨论(0)
提交回复
热议问题