[英]How to get api from database network using database ,username ,password in react native
I'm setting up My connection with SAP Service layer one.我正在建立与 SAP Service 第一层的连接。 I have used static API but this time want to connect to API using我使用过 static API 但这次想使用 API 连接到
[
username: { UserName: 'MySAPUserName', DBCompany: MySAPDBName },
Password: "MySAPPassword"
]
I don't know how to setup connection in react native using this basic authentication.我不知道如何使用此基本身份验证在本机反应中设置连接。
I trie some of the solution but failed to get the response我尝试了一些解决方案,但未能得到响应
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);
});
I am not sure if you have these variables in scope, since you have only shared a snippet.我不确定您在 scope 中是否有这些变量,因为您只共享了一个片段。 But assuming these are variables, the string concatenation is wrong.但是假设这些是变量,则字符串连接是错误的。 and the structure also seems wrong而且结构似乎也错了
headers.append("Authorization", "Basic " + base64.encode('{"UserName":"'+MySAPUserName+'","DBCompany":"'+MySAPDBName+'", "Password":"'+MySAPPassword+'"}'));
A better approach would be to create an object and stringify it like below更好的方法是创建一个 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.