问题描述
我想在伪造者的标头中传递身份验证令牌(JWT),以便在我的应用程序中使用无头chrome的pdf视图吗?我们正在使用react作为前端UI.使用puppeteer,我们能够生成pdf,但是我们需要使用JWT授权到pdf的链接我们如何在标头中传递jwt,puppeteer是否支持标头中的Auth令牌?请帮忙.
I want to pass authentication token(JWT) in puppeteer headers, for the pdf view with headless chrome in my application?We are using react as our front-end UI. And using puppeteer we are able to generate pdf, but the link to pdf we need to authorize using JWTHow do we pass the jwt in headers, does puppeteer support Auth token in headers?Please help.
谢谢
推荐答案
要在请求中传递其他标头,可以使用函数 page.setExtraHTTPHeaders
.
To pass additional headers in the request, you can use the function page.setExtraHTTPHeaders
.
上面链接的文档中的语录:
Quote from the docs linked above:
示例:
page.setExtraHTTPHeaders({
'Token': '...',
});
随后所有后续请求都将具有带有设置值的附加标头Token
.
All following requests will then have the additional header Token
with the set value.
这篇关于我们如何在Google puppeteer的无头Chrome中传递身份验证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!