IIS和放大器;铬:未能加载资源:净:: ERR_INCOMPLETE_CHUNKED_ENCODING [英] IIS & Chrome: failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

查看:4251
本文介绍了IIS和放大器;铬:未能加载资源:净:: ERR_INCOMPLETE_CHUNKED_ENCODING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我遇到了一个Chrome的问题,我认为这是值得与大家分享。



我的工作自写的API使用一个HttpHandler这主要应该返回JSON数据。但是,当一个错误occures我想显示一个html文件。 。这工作得很好在IE和FF,但不能在Chrome



展望开发工具揭示了这个错误:净:: ERR_INCOMPLETE_CHUNKED_ENCODING



谷歌表示并不非常关注这个问题,而这是看到非常多。所有我知道的是,这是一段时间后,奇迹般地消失了。



我发现它奠定了在这个代码行:

  result.StoreResult(背景); 
context.Response.Flush();
context.Response.Close(); //< - 这将导致错误



删除最后它的工作好线后。我不知道为什么只有铬有/有,一个问题,但它好像我关闭响应流之前的镀铬读完它。



我希望它。帮助那些你在相同或类似的问题,未来的



现在我的问题:
如何在闭幕最好的初步实践/冲洗响应流?有没有什么规则?


解决方案

据的ASP.NET设置传输编码上过早刷新响应为分块:




ASP.NET数据到客户端的传输分块编码(Transfer-Encoding的:分块),如果你过早冲洗的响应流Http请求和Content-Length头的响应没有明确由您定。



解决方案:你需要明确设置Content-Length头的响应,以防止从ASP.NET上分块刷新响应




下面是我用于防止ASP.NET从分块设置所需要的头响应的C#代码:



<预类=郎-CS prettyprint-覆盖> 保护无效writeJsonData(字符串s){
HttpContext的背景下= this.Context;
的HttpResponse响应= context.Response;
context.Response.ContentType ="文/ JSON英寸;
的byte [] B = response.ContentEncoding.GetBytes(S);

response.AddHeader(QUOT; Content-Length的" ;, b.Length.ToString());

response.BinaryWrite(二);

{
this.Context.Response.Flush();
this.Context.Response.Close();
}
赶上(例外){}
}


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 json data. But when an error occures I wanted to display an html file. That worked pretty well in IE and FF, but not in Chrome.

Looking to the developer tools revealed this error: net::ERR_INCOMPLETE_CHUNKED_ENCODING

Google said not very much about this issue while it was seen very much. All I got to know was, that it was magically disappearing after some time.

I found out it lays on this lines of code:

result.StoreResult(context);
context.Response.Flush();
context.Response.Close(); //<-- this causes the error

After removing the last line it worked well. I don´t know why only Chrome had/has an issue with that, but it seemed as if I closed the response stream before chrome finished reading it.

I hope it helps those of you coming across the same or a similar issue.

Now my question: How is the best pratice in closing/flushing the response stream? Are there any rules?

解决方案

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) { }
}

这篇关于IIS和放大器;铬:未能加载资源:净:: ERR_INCOMPLETE_CHUNKED_ENCODING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆