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

时间:2019-08-27 20:07:16

标签: javascript axios

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

与邮递员一起使用它没有问题,我只需要对查询字符串(电子邮件)进行编码,因为“ @”不是有效字符。

我使用一个网站对电子邮件进行编码,并且可以正常工作。我使用了邮递员并添加了基本身份验证凭据

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

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');
});

1 个答案:

答案 0 :(得分:0)

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

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