正在从响应中解析 cache-control header 值
Parsing cache-control header value from response
我需要解析 cache-control header 响应以从缓存 API 响应中使用它。
响应示例 headers:
{"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"]
我需要解析 cache-control header 响应以从缓存 API 响应中使用它。
响应示例 headers:
{"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"]