简体   繁体   中英

Ignore Content-Length of an http response

I need to make an http request to an external service which indicates that it has a mismatch on the Content-Length of its response. I can't find information about how to ignore that Content-Length or if it affects to the length of the response body.

This is the code that I have been using to make the request:

req = Net::HTTP::POST.new(url, headers)
req.body = body
http = Net::HTTP.new(url.host, url.port)
response = http.request(req)
body = JSON.parse(response.body)

First of all, it's very unlikely that the Content-Length is not set correctly by any service, as it's virtually never set manually, it belongs to the underlying HTTP layer itself, and is set with corresponding libraries which are thoroughly tested.

And even if it's not, I don't think it's a good idea to "ignore" it, better contact the service provider and point them to the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM