Reputation: 1232
I have a curl like this
curl -u 209f734234234j556l45l6j64218ecffb0a900aff998c8e0: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: 123k4j54k" https://push.ionic.io/api/v1/push -d '{"tokens": ["token1,token2,token3"],"notification":{"alert":"NarayaN","android":{"payload":{"$state":"app.home"}}}}'
Which i have converted it to this state
var request = require('request');
var headers = {
'Content-Type': 'application/json',
'X-Ionic-Application-Id': 'e4ea3c2d'
};
var options = {
url: 'https://push.ionic.io/api/v1/push',
headers: headers
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
I am having trouble with -u param. How to use that in http req
By looking at the req i can see that the method is post
Any Help is much appreciated.
Upvotes: 0
Views: 133
Reputation: 594
You can use .auth()
method
request.get('http://some.server.com/').auth('username', 'password', false);
// or
request.get('http://some.server.com/', {
'auth': {
'user': 'username',
'pass': 'password',
'sendImmediately': false
}
});
// or
request.get('http://some.server.com/').auth(null, null, true, 'bearerToken');
// or
request.get('http://some.server.com/', {
'auth': {
'bearer': 'bearerToken'
}
});
https://github.com/request/request#http-authentication
Or
https://github.com/request/request#oauth-signing
Upvotes: 1