久久久久久久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ū)別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

何時使用隱藏字段,何時使用標題以及為什么?
X-XSRF_TOKEN 什么時候使用?
X-CSRF TOKEN我們什么時候使用?

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

推薦答案

所有這些都是為了跨站點請求偽造保護,并且您只需要使用其中一個即可向后端發(fā)送請求.不同的名稱來自不同的框架.

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.

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

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 表單時在后端生成.
  • 我們無法直接在 html 表單中設置請求頭,因此一種簡單的方法是通過表單輸入將其作為隱藏字段發(fā)送.
  • 你可以隨意命名這個隱藏的輸入.例如

x-csrf-token:

  • 它被添加到請求ajax請求的頭.
  • 要使用它,我們可以在渲染 html 時將 csrf 值 放在一個元標記中,然后在前端我們可以從該元標記中獲取值并將其發(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 作為后端時.Laravel 會自動檢查此標頭并將其與數(shù)據(jù)庫中的有效 csrf 值 進行比較.(laravel 有一個中間件)
  • 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:

  • 它被添加到請求ajax請求的頭.
  • angular 和 axios 等流行庫,會自動從 xsrf-token cookie 中獲取此標頭的值并將其放入每個請求標頭中.
  • 要使用它,我們應該在后端創(chuàng)建一個名為 xsrf-token 的 cookie,然后我們使用 angular 或 axios 的前端框架會自動使用它.
  • 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:

  • 因為它很受歡迎,所以 Laravel 在每個響應中都會創(chuàng)建這個 cookie.
  • 所以當你使用 axiosangularlaravel 時,你不需要做任何事情.只需登錄用戶,'auth' 中間件就可以完成這項工作.
  • 在 laravel 中,與 x-csrf-token 相比,它是一個更大的字符串,因為 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.

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(liá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(響應內(nèi)容必須是實現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動到 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在线免费观看网站 | 久久精品免费一区二区三 | 九七午夜剧场福利写真 | 成人超碰在线 | 日韩一区二区三区视频在线播放 | 天天拍天天色 | www.玖玖玖| 人人人艹 | 亚洲成人免费在线 | japanhdxxxx裸体| 久久精品国产一区二区三区 | 欧美在线日韩 | 99精品欧美| 日日干天天操 | 天天澡天天狠天天天做 | 九九伦理片 | 精品国产一区一区二区三亚瑟 | 妖精视频一区二区三区 | 三级视频在线观看电影 | 中文字幕第100页 | 色综合中文 | 一级少妇女片 | 久久精品屋 | 中文字幕av中文字幕 | 国产欧美精品一区二区色综合朱莉 | 黄色毛片大全 | 国产精品欧美一区二区 | 欧美中文一区 | 国产精品色哟哟网站 | 麻豆久久久久久 | 欧美精品久久久久 | 国产精品成人国产乱一区 | 青青久草 | av黄色片| 日日夜夜91 | 亚洲精品久久久久avwww潮水 | 69av片| 日韩免费视频一区二区 | 91在线第一页 | 亚洲男女激情 |