简体   繁体   English

如何使用数据库、用户名、密码从数据库网络获取 api

[英]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.

相关问题 如何在本机反应中从firestore数据库中获取字段值 - How to get field value from firestore database in react native 如何使用javascript / ajax或任何其他验证格式来验证用户名和密码以及从数据库中选择的角色 - How to validate the username and password and also the selected role from database using javascript/ajax or any other validation formats 如何在Axios中使用用户名和密码访问数据库 - How to access database with username and password in Axios 我可以从Wordpress数据库中获取React应用程序的用户密码吗? - Can I get user password from Wordpress database for React application? 如何从使用密码和用户名的位获取访问令牌? - how to get access token from bitly using password and username? 我如何调用 API 并在 javascript 中使用数据库检查用户名和密码? - How do I go about calling API and check username and password with Database in javascript? 如何在React Native Linking中传递用户名和密码? - How can I pass username and password in React Native Linking? 如何从React Native中的TextField获取值,由于空值而无法将数据存储到数据库 - How to get value from TextField in React Native, Unable to store data to database caused by null value 从数据库到jsp视图页面的用户名和密码验证 - Username and password validation from database to jsp view page 在 PHP 中验证数据库中的用户名和密码后,如何使按钮转到特定页面 - How do you make a button go to a specific page after validating the Username and Password from the Database in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM