日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SAP UI5 应用读取 CSRF token 的 HTTP head 请求逻辑解析

發布時間:2023/12/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP UI5 应用读取 CSRF token 的 HTTP head 请求逻辑解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SAP UI5 應用在發送 OData batch 請求之前,會通過下列的_createBatchRequest方法構造 batch 請求對象:

var oBatchRequest = that._createBatchRequest(aReadRequests);

該請求對象的 data 字段里,包含 batch 具體的 payload:

  • Invoices?KaTeX parse error: Expected 'EOF', got '&' at position 7: skip=0&?top=100&$orderby=ShipperName%20asc
  • Invoices/$count

該請求頭部字段 Accept 為 multipart/mixed:

然后通過 oWrappedBatchRequestHandle.oRequestHandle = that._submitBatchRequest(oBatchRequest, aBatchGroup, fnSuccess, fnError) 方法進行提交。

token handling 標志位為 true,且方法不為 POST,因此在執行 batch 操作之前,先要獲取 CSRF token:

進入函數refreshSecurityToken.

構造發起 token 請求的 request 對象:

url 為:https://services.odata.org/V2/Northwind/Northwind.svc/

首先嘗試 head 請求,如果報錯,再切換成 get 請求:

// Initially try method "HEAD", error handler falls back to "GET" unless the flag forbids HEAD requestif (this.bDisableHeadRequestForToken) {mTokenRequest.request = requestToken("GET", handleGetError);} else {mTokenRequest.request = requestToken("HEAD", handleHeadError);}

請求 token 的 HTTP 請求的 Content-type 設置邏輯,和標志位 bJson 有關:

request 對象:

最重要的頭部字段 x-csrf-token, 值被填充成 fetch:

function requestToken(sRequestType, fnError) {// trigger a read to the service url to fetch the tokenoRequest = that._createRequest(sUrl, "", sRequestType,that._getHeaders(undefined, true), null, null, !!bAsync);oRequest.headers["x-csrf-token"] = "Fetch";return that._request(oRequest, handleSuccess, fnError, undefined, undefined, that.getServiceMetadata());}

執行了 head 請求后,響應的狀態碼是 200,但是 responseText 字段值是空的。

還是進入 success callback:

使用 handler 讀取 token 請求的 response,這個 handler 支持的 content-type 類型:application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, /;q=0.1

這里因為 response.body 是空的,因此進入不了 dispatchHandler的處理邏輯:

然后進入 refreshToken 的 callback:

當然是拿不到 token 的:

進入 else 分支:

清除所有相關的 token 標志位:

ODataModel.prototype.resetSecurityToken = function() {delete this.oSharedServiceData.securityToken;delete this.oHeaders["x-csrf-token"];delete this.pSecurityToken;};

resolve 一個空的 token 給 callback:

這個 head 請求的響應碼為 200,但是響應頭部沒有附帶 csrf token:

更多Jerry的原創文章,盡在:“汪子熙”:

總結

以上是生活随笔為你收集整理的SAP UI5 应用读取 CSRF token 的 HTTP head 请求逻辑解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。