2016-12-14 29 views
0
var Array = require('node-array'); 
    var request = require("request"); 
username = "user24", 
password = "", 
     auth = "Basic " + new Buffer(username + ":" + password).toString("base64"); 
var options = { method: 'GET', 
url: "http://207.188.73.88:8000/sap/opu/odata/sap/ZTEE_SUGGEST_SRV/ZteeSuggestSet?$filter=Number eq 5 and Date eq datetime'2014-03-11T00%3A00%3A00'&$format=json", 
headers: 
{ 

我正在獲取xcsrf令牌這裏CSRF令牌驗證在後請求失敗,同時呼籲SAP OData服務

'x-csrf-token': 'fetch', 
    'content-type': 'application/json', 
    authorization: auth } }; 

     request(options, function (error, response, body) { 
      if (error) throw new Error(error); 
    // console.log(response.headers['x-csrf-token']); 
    var token="'"; 
     token+=response.headers['x-csrf-token']; 
     token+="'"; 
     //console.log(token); 
     var options = { method: 'POST', 
    url: 'http://207.188.73.88:8000/sap/opu/odata/sap/ZTEE_TIME_SRV/ZTEERESERVESet', 

和令牌這裏設置CSRF,但它給我的錯誤,需要SCRF令牌或無效

headers: 
    { 
authorization: auth, 
'x-csrf-token': token, 
'content-type': 'application/json' }, 
body: 
{ Time: 'time\'PT11H00M00S\'', 
Date: 'datetime\'2014-03-11T00%3A00%3A00\'', 
Location: 'AAJ', 
Number: 3 }, 
json: true }; 

    request(options, function (error, response, body) { 
     if (error) throw new Error(error); 

// console.log(body); 這表明令牌rrequired,但我已經設置在報頭

    console.log(response.headers['x-csrf-token']); 
      }); 




     }); 
+0

您是否找到了解決方案?我陷入了同樣的問題 – Mikel

回答

1

我曾面臨類似的情況與SAP WEBIDE工作時。

我已經禁用令牌請求,並且能夠與Odata服務建立連接。我在我的component.js文件中做了這樣的代碼片段。

var oModel = new sap.ui.model.odata.ODataModel(this.getMetadata().getConfig().serviceUrl); 
oModel.disableHeadRequestForToken = true; 

的serviceURL包含的URL OData服務。 您可以嘗試禁用CSRF令牌請求並進行檢查。

相關問題