I try use promise-request and write code:
var pr = require('promise-request');
var options = {
method: 'POST',
uri: 'http://localhost:4000/user/login',
port: 4000,
form: {
login: 'login',
password: 'password'
},
json: true
};
pr(options)
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
});
If don't use port options I got error:
Error: connect ECONNREFUSED 127.0.0.1:80
And if I add port options error disappear but in official docs don't write about that you can set this option. And it is strage that it works because I set port in uri. I have error that I can not get data from server. I got only error:
undefined:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token < in JSON at position 0
I do same request with http module and all works good maybe I need use another module?
via Metal Evolution Studio
No comments:
Post a Comment