gpt4 book ai didi

angularjs - Angular 的用户名和密码认证

转载 作者:可可西里 更新时间:2023-11-01 16:30:02 26 4
gpt4 key购买 nike

我正在尝试部署一个 flask+angular 应用程序,其中 flask 托管在 Digital Ocean ubuntu 服务器上。

api是基于这个guide .

在 curl 中,我可以通过以下方式确认它是否有效:curl -u <username>:<passwd> -i -X GET https://<server>

我尝试使用 http 获得相同的 Angular :

$http.get('https://<server>',
{username: <user>, password: <password>})
.then(function(response){
console.log(response.data});

导致 401 UNAUTHORIZED

我希望你能在这里帮助我。

最佳答案

您可以使用post 方法代替get 来发送数据

$http.post('https://<server>', 
{username: <user>, password: <password>})
.then(function(response){
console.log(response.data);
});

并在服务中通过 req.body.username 获取。我假设服务器端是“node.js”,这就是使用“req.body”的原因。

然后还需要在服务器端使用post 方法来接受您对urlpost 请求。

如果你想使用get方法,那么你可以像params一样发送数据

var config = {
params: {username: <user>, password: <password>},
headers : {'Accept' : 'application/json'}
};

$http.get('https://<server>', config).then(function(response) {
// process response here..
console.log(response.data);
});

关于angularjs - Angular 的用户名和密码认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36372468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com