![](/img/trans.png)
[英]How to get the content-length of the response from a request with fetch()
[英]get content-length from request headers, node
我正在向網站提出獲取請求,並希望從響應headers
獲取content-length
。
import rp from "request-promise";
const options = {
uri: "http://www.dadaabstories.org/",
resolveWithFullResponse: true
};
rp(options).then(res => {
console.log(res.headers);
}).catch(err => {
throw err;
});
我得到的響應沒有content-length
:
服務器:“ openresty”,
日期:'2019年3月5日,星期二',
'content-type':'文本/ html; 字符集= UTF-8' ,
'transfer-encoding':'chunked',
連接:“關閉”,
不同:“接受編碼,X-UA設備,接受,接受編碼”,
'x-rid':'adbfe4b6b62c7a71bce234e33a6f07f5',
p3p:someData',
'x-xss-protection':'1; 模式=塊”,
'x-content-type-options':'someData',
'x-tumblr-user':'someData',
'x-tumblr-pixel-0':'someData',
'x-tumblr-pixel-2':'someData',
'x-tumblr-pixel':'someData',
鏈接:“ someData”,
'x-robots-tag':'noindex,nofollow',
'x-ua-compatible':'someData',
'x-ua-device':'someDevice'
但是對於這個演示網站http://stack.imgur.com/
我得到了content-length
。
我已經學會從這個那個'transfer-encoding': 'chunked'
被禁止content-length
。 那我怎么能得到呢?
就像Chrome瀏覽器顯示尺寸的方式一樣。 甚至我試圖得到的不是contetn-length
答復。
這是網站后端的一種方式。 如果服務器默認情況下不包含Content-Length(通常在文件交換期間包含它),則通常HTTP協議中不可能明確詢問您想要的標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.