如何查看这些特定的响应标头?

问题描述 投票:0回答:1

我正在使用 Twitch 的 API 为我正在开发的网络应用程序收集数据。

根据文档,

但是,当我在Postman中发出请求时,我没有看到它。

它们位于标头响应部分(我没有截图剩下的一半响应)。

我是不是看错地方了?

我查看了我发出的 API 请求的标头响应部分。此外,我还查看了控制台中的“标头请求”部分。

postman http-headers httpresponse twitch-api
1个回答
0
投票

Postman 中的 headers 选项卡是请求(输入)标头而不是响应(输出)标头数据。 它位于输出区域。

您可以在

Test
选项卡中查看(或分配)响应标头。

另外

curl
的 -v 选项可以看到来自 tesminal 的标头。

curl --location 'http://localhost:5000/user' \
-v \
--header 'Content-Type: application/json' \
--data '{
    "username": "username",
    "password": "1234"
}'

结果

您可以通过脚本在

Test
选项卡上查看或分配变量

headers = pm.response.headers.all();
jsonHeader = JSON.stringify(headers);
console.log(jsonHeader)

headers.forEach(function(header){
    if(header.key == "Ratelimit-Reset"){
        pm.globals.set("Ratelimit-Reset", header.value)
        console.log(header.value)
        return;
    }    
})

您可以为特定键/值分配全局变量

Python Flask 的演示服务器(模拟您的 Twitch 的 API 服务器)。

app = Flask(__name__)

@app.route("/user", methods=["POST"])
def post_test():
    content_type = request.headers.get('Content-Type')
    if (content_type == 'application/json'):
        resp = Response(request.get_json())
        resp.headers['x-amzn-Requestid'] = '20122de8-3fd9-4439-b7f8-5c76a9dcf77e'
        resp.headers['x-amzn-Remapped-Content-Length'] = '6dd53770-ffa0-4f5f-95e6-b2fabe98c483'
        resp.headers['x-amz-apigw-id'] = 'e2994bb8-22c2-4ac5-b936-b541ac1bf99b'
        resp.headers['x-amzn-Rmapped-Date'] = '2023-08-17 16:45:43 UTC'
        resp.headers['x-Count'] = '1234'
        resp.headers['Ratelimit-Limit'] = '150'
        resp.headers['Ratelimit-Remaining'] = '98'
        resp.headers['Ratelimit-Reset'] = '1692306166'
        return resp, 201
    else:
        return 'Content-Type not supported!'

if __name__ == "__main__":
    app.run(debug=True)

详细信息请参见here,用于安装依赖项并运行它。

© www.soinside.com 2019 - 2024. All rights reserved.