cURL取得HTTP回應頭(response headers)的方式如下。
cURL在發送請求時加上-i
或--include
即可取得response headers。
例如下面輸入curl https://api.github.com/zen -i
發送請求給GitHub的測試API https://api.github.com/zen
並取得response headers。
$ curl https://api.github.com/zen -i
HTTP/2 200
server: GitHub.com
date: Thu, 14 Jul 2022 00:09:54 GMT
content-type: text/plain;charset=utf-8
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
vary: Accept-Encoding, Accept, X-Requested-With
x-ratelimit-limit: 60
x-ratelimit-remaining: 58
x-ratelimit-reset: 1657760993
x-ratelimit-resource: core
x-ratelimit-used: 2
accept-ranges: bytes
content-length: 26
x-github-request-id: E3E4:4AF7:2550B:362EF:62CF5EDA
Favor focus over features.
沒有留言:
張貼留言