久久久久久久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ì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

何時(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)求.不同的名稱來自不同的框架.

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ì)將其與該特定用戶的數(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í)在后端生成.
  • 我們無法直接在 html 表單中設(shè)置請(qǐng)求頭,因此一種簡(jiǎn)單的方法是通過表單輸入將其作為隱藏字段發(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í),你不需要做任何事情.只需登錄用戶,'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)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
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 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 91麻豆精品一区二区三区 | av日韩一区| 91久久精品国产91久久 | av性色全交蜜桃成熟时 | 一区二区三区精品视频 | 日本在线免费 | 夜夜爽99久久国产综合精品女不卡 | 在线看国产 | 午夜影院在线视频 | 一区二区三区在线播放视频 | 国产精品久久久久久久久久久免费看 | 日日夜夜操天天干 | 美女福利视频一区 | 精品欧美乱码久久久久久 | 成人免费看黄网站在线观看 | v片网站| 色妞av| 国产精品一区二区三区久久 | 日日爱夜夜操 | 男人的天堂视频网站 | 一区二区三区四区毛片 | 一区二区三区在线电影 | 欧美日韩激情 | 完全免费在线视频 | 久久一区视频 | 日韩91| 成人做爰www免费看视频网站 | av网站在线看 | 国产精品欧美一区二区三区不卡 | 亚洲精品黄色 | 欧美福利一区 | 精品久久伊人 | 日韩视频在线观看一区二区 | 午夜影视 | 亚洲精品成人网 | 久久久久久久国产精品视频 | 日本一区二区电影 | 欧美精品在线一区二区三区 | a毛片| 午夜视频在线播放 | 欧美精产国品一二三区 |