問題描述
我有一個使用 jwt
進行身份驗證的 api
.我正在將此 api 用于 vuejs
應用程序.我正在嘗試使用
I have an api
that uses jwt
for authencation. I am using this api for a vuejs
app. I am trying to display an image in the app using
<img src="my/api/link" />
但是 api
需要 Authorization
標頭,其中包含 jwt token
.
But the api
expects Authorization
header with jwt token
in it.
我可以像這樣在瀏覽器請求中添加標頭嗎(這里對幾個問題的回答讓我相信這是不可能的)?
Can I add headers to browser request like this(Answer to few questions here has made me believe it's not possible)?
有什么方法可以解決(使用 js)還是我應該更改 api
本身?
Is there any way around it(using js) or should i change the api
itself?
推薦答案
img標簽中直接用作href的圖片不能進行認證.如果你真的想對你的圖像進行這種類型的身份驗證,那么最好使用 ajax 獲取它們,然后嵌入到你的 html 中.
You can not perform authentication on images which are directly used as href in img tag. If you really want this type of authentication on your images, then it's better to fetch them using ajax and then embed in your html.
這篇關于img src 鏈接中的授權標頭的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!