服务器有时会返回分块传输编码 [英] server sometimes returns chunked transfer encoding

查看:50
本文介绍了服务器有时会返回分块传输编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 REST API.. 有时服务器会使用分块传输编码返回响应?这是为什么?!

I'm building a REST API.. Sometimes the server returns the response with chunked transfer encoding? Why is that?!

为什么服务器不能总是以相同的编码返回响应?

Why can't the server always return the response in the same encoding?

问题是当数据以分块形式返回时,我不知道如何读取数据!?

The problem is that I don't know how to read the data when its returned as chunked!?

需要moore downvotes...到breeeath...

neeed moore downvotes... to breeeath...

推荐答案

假设您的服务器使用 Apache,这是预期行为.您可以通过将此行放在 .htaccess 文件中来禁用它:

Assuming your server is using Apache, this is expected behaviour. You can disable it by putting this line in your .htaccess file:

SetEnv downgrade-1.0

但是,您应该考虑修改您的阅读代码以仅支持不同的内容编码.您使用什么库来发出 HTTP 请求?任何合理的 HTTP 库都可以处理分块请求.如果您的请求代码是用 PHP 编写的,请使用 curl.http://php.net/manual/en/book.curl.php

However, you should consider modifying your reading code to just support different content encodings. What library are you using to make the HTTP request? Any reasonable HTTP library can handle chunked requests. If your requesting code is written in PHP, use curl. http://php.net/manual/en/book.curl.php

这篇关于服务器有时会返回分块传输编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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