[英]Parsing cache-control header value from response
我需要解析緩存控制標頭響應,以便通過緩存API響應來使用它。
樣本響應頭:
{"x-backside-transport":"OK OK","connection":"close","transfer-encoding":"chunked","access-control-allow-origin":"*","cache-control":"public, max-age=60","content-type":"application/json","date":"Thu, 05 Oct 2017 10:33:59 GMT","etag":"\"-161458570\"","x-powered-by":"Express","x-global-transaction-id":"429271565"}
我正在使用console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.cache-control));
但這似乎每次都會失敗。
給我錯誤: ReferenceError: control is not defined
但是當它嘗試與
console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.connection));
我能夠成功打印出日志值。 我想念什么嗎?
破折號-
不適用於JSON。 您可能想嘗試如下解析
response.headers["cache-control"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.