久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

X-XSRF-TOKEN 和 X-CSRF-TOKEN 有什么區(qū)別?

what is the difference between X-XSRF-TOKEN and X-CSRF-TOKEN?(X-XSRF-TOKEN 和 X-CSRF-TOKEN 有什么區(qū)別?)
本文介紹了X-XSRF-TOKEN 和 X-CSRF-TOKEN 有什么區(qū)別?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

何時(shí)使用隱藏字段,何時(shí)使用標(biāo)題以及為什么?
X-XSRF_TOKEN 什么時(shí)候使用?
X-CSRF TOKEN我們什么時(shí)候使用?

When use hidden field and when use header and why ?
X-XSRF_TOKEN when we use?
X-CSRF TOKEN when we use?

推薦答案

所有這些都是為了跨站點(diǎn)請(qǐng)求偽造保護(hù),并且您只需要使用其中一個(gè)即可向后端發(fā)送請(qǐng)求.不同的名稱(chēng)來(lái)自不同的框架.

All of them are for cross site request forgery protection and you need to use just one of them when sending a request to backend. Different names come from different frameworks.

這一切都是關(guān)于向后端發(fā)送一個(gè) csrf 值.然后后端會(huì)將其與該特定用戶(hù)的數(shù)據(jù)庫(kù)中存儲(chǔ)的 csrf 值進(jìn)行比較,如果匹配,則允許處理請(qǐng)求.

It's all about sending a csrf value to backend. Then backend will compare it with the csrf value stored in database for that specific user and if it matches, it will allow processing the request.

csrf :

  • 用于 html 表單(不是 ajax)
  • 在渲染 html 表單時(shí)在后端生成.
  • 我們無(wú)法直接在 html 表單中設(shè)置請(qǐng)求頭,因此一種簡(jiǎn)單的方法是通過(guò)表單輸入將其作為隱藏字段發(fā)送.
  • 你可以隨意命名這個(gè)隱藏的輸入.例如

x-csrf-token:

  • 它被添加到請(qǐng)求ajax請(qǐng)求的頭.
  • 要使用它,我們可以在渲染 html 時(shí)將 csrf 值 放在一個(gè)元標(biāo)記中,然后在前端我們可以從該元標(biāo)記中獲取值并將其發(fā)送到后端.
  • It is added to the request header for ajax requests.
  • To use it, we can put the csrf value in a meta tag while rendering the html, then in front end we can get the value from that meta tag and send it to backend.

Laravel 特定:

Laravel specific:

  • 使用 laravel 作為后端時(shí).Laravel 會(huì)自動(dòng)檢查此標(biāo)頭并將其與數(shù)據(jù)庫(kù)中的有效 csrf 值 進(jìn)行比較.(laravel 有一個(gè)中間件)
  • When using laravel as backend. Laravel checks this header automatically and compares it to the valid csrf value in database.(laravel has a middleware for this)

x-xsrf-token:

  • 它被添加到請(qǐng)求ajax請(qǐng)求的頭.
  • angular 和 axios 等流行庫(kù),會(huì)自動(dòng)從 xsrf-token cookie 中獲取此標(biāo)頭的值并將其放入每個(gè)請(qǐng)求標(biāo)頭中.
  • 要使用它,我們應(yīng)該在后端創(chuàng)建一個(gè)名為 xsrf-token 的 cookie,然后我們使用 angular 或 axios 的前端框架會(huì)自動(dòng)使用它.
  • It is added to the request header for ajax requests.
  • Popular libraries like angular and axios, automatically get value of this header from xsrf-token cookie and put it in every request header.
  • To use it, we should create a cookie named xsrf-token in backend, then our front end framework that uses angular or axios will use it automatically.

Laravel 特定:

Laravel specific:

  • 因?yàn)樗苁軞g迎,所以 Laravel 在每個(gè)響應(yīng)中都會(huì)創(chuàng)建這個(gè) cookie.
  • 所以當(dāng)你使用 axiosangularlaravel 時(shí),你不需要做任何事情.只需登錄用戶(hù),'auth' 中間件就可以完成這項(xiàng)工作.
  • 在 laravel 中,與 x-csrf-token 相比,它是一個(gè)更大的字符串,因?yàn)?cookie 在 laravel 中是加密的.
  • Because it's popular, laravel creates this cookie in each response.
  • so when you're using for example axios or angular with laravel, you don't need to do anything. just log user in and 'auth' middleware will do the job.
  • In laravel, its a bigger string compared to x-csrf-token because cookies are encrypted in laravel.

這篇關(guān)于X-XSRF-TOKEN 和 X-CSRF-TOKEN 有什么區(qū)別?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢(xún))
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數(shù))
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數(shù)中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應(yīng)內(nèi)容必須是實(shí)現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動(dòng)到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問(wèn)某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 午夜一区 | 国产精品99久久久久久www | av天天干 | 午夜视频免费 | 午夜视频在线看 | 国产97视频 | 成人自拍视频在线观看 | 午夜在线观看免费视频 | 欧美综合视频 | 亚洲精品国产一区 | 日韩av在线一区 | 亚洲天堂日本 | 欧美视频久久 | 色婷婷视频在线观看 | 亚洲欧美精品一区二区 | 国产精品一 | 国产逼逼 | 日韩高清精品免费观看 | 久久久久久久久久国产 | 狠狠插狠狠操 | 免费不卡视频 | 久久99久久久 | 欧美一级淫片免费视频黄 | 在线观看成人免费视频 | 黄色三级在线观看 | 亚洲国产精品久久久久 | 91黄色片| 日韩成人小视频 | 亚洲国产欧美日韩 | 99国产精品99久久久久久 | 国产最新av | 日韩黄色在线 | 两性免费视频 | 国产aⅴ爽av久久久久成人 | 三级福利视频 | 天天插天天干 | 国产又粗又大又爽 | 精品在线播放 | www.狠狠操 | 一区二区三区免费在线观看 | 久久精品一区二区三区四区 |