[英]How to get api from database network using database ,username ,password in react native
我正在建立與 SAP Service 第一層的連接。 我使用過 static API 但這次想使用 API 連接到
[
username: { UserName: 'MySAPUserName', DBCompany: MySAPDBName },
Password: "MySAPPassword"
]
我不知道如何使用此基本身份驗證在本機反應中設置連接。
我嘗試了一些解決方案,但未能得到響應
var headers = new Headers();
headers.append("Authorization", "Basic " + base64.encode('{UserName:'MySAPUserName',DBCompany:MySAPDBName}:MySAPPassword'));
fetch("https://EEPLhana:50000/b1s/v1/ProjectsService_GetProjectList",{
headers: headers
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch((error) =>{
console.error(error);
});
我不確定您在 scope 中是否有這些變量,因為您只共享了一個片段。 但是假設這些是變量,則字符串連接是錯誤的。 而且結構似乎也錯了
headers.append("Authorization", "Basic " + base64.encode('{"UserName":"'+MySAPUserName+'","DBCompany":"'+MySAPDBName+'", "Password":"'+MySAPPassword+'"}'));
更好的方法是創建一個 object 並將其字符串化,如下所示
let auth = { Username: MySAPUserName, DBCompany: MySAPDBName, Password: MYSAPPassword };
headers.append("Authorization", "Basic " + base64.encode(JSON.stringify(auth)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.