Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

server sometimes returns chunked transfer encoding

Tags:

php

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!?

update

neeed moore downvotes... to breeeath...

like image 492
clarkk Avatar asked Jun 18 '26 02:06

clarkk


2 Answers

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

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

like image 71
Cal Avatar answered Jun 19 '26 18:06

Cal


Taken from Server Fault:

  1. specify the "Content-Length' header, so server knows, what's the size of the response
  2. use HTTP 1.0 at the requester's side
like image 45
zemiak Avatar answered Jun 19 '26 18:06

zemiak