server sometimes returns chunked transfer encoding

前端 未结 3 1219
旧时难觅i
旧时难觅i 2020-12-20 03:23

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

相关标签:
3条回答
  • 2020-12-20 03:54

    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

    0 讨论(0)
  • 2020-12-20 04:00

    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
    0 讨论(0)
  • 2020-12-20 04:03

    A problem may be that Apache is gzipping your download, taking care of correcting the Content-Length, or in your case, adding the header

    Content-Encoding: chunked

    You can add a .htaccess RewriteRule to disable gzip:

    RewriteRule . - [E=no-gzip:1]
    
    0 讨论(0)
提交回复
热议问题