电子邮件编码和基本身份验证的反应



我的 API 看起来像这样 https://customerlink.org/api/data?email=">

我用邮递员没有问题,我只需要对查询字符串(电子邮件(进行编码,因为"@"不是有效字符。

我使用一个网站对电子邮件进行编码,它没有问题。我使用了邮递员并添加了基本身份验证凭据

但是我对如何添加电子邮件部分以及如何从我的 react 应用程序对其进行编码感到困惑。

var api_url = "https://customerlink.org/api/data?email="
var email = "testemail@gmail.com"
var username = 'username';
var password = 'password';
var basicAuth = 'Basic ' + btoa(username + ':' + password);
axios.post(api_url + email, {}, {
headers: { 'Authorization': + basicAuth }
}).then(function(response) {
console.log('Authenticated');
}).catch(function(error) {
console.log('Error on Authentication');
});

如果需要,可以使用encodeURI(uri),但 @ 符号可以在查询字符串中使用即可。

let uri = "https://customerlink.org/api/data?email=my@email.com"
let encodedUri = encodeURI(uri);

最新更新