Reputation: 3423
I am trying to deploy a flask+angular app, where flask is hosted on a Digital Ocean ubuntu server.
The api is based on this guide.
In curl I can confirm it works by: curl -u <username>:<passwd> -i -X GET https://<server>
I try to obtain the same in angular using http:
$http.get('https://<server>',
{username: <user>, password: <password>})
.then(function(response){
console.log(response.data});
Results in a 401 UNAUTHORIZED
I hope you can help me here.
Upvotes: 2
Views: 4534
Reputation: 16805
You can use post
methods instead of get
to send data
$http.post('https://<server>',
{username: <user>, password: <password>})
.then(function(response){
console.log(response.data);
});
and in serve get by req.body.username
. I assume server side is 'node.js' that's why used 'req.body'.
then also need post
method in server side to accept your post
request for your url
.
OR
If you want to use get
method then you can send data as a params
like
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);
});
Upvotes: 3