我正在尝试使用标准POST login
请求登录到在Web服务器上运行的回送API。但是,每次运行它,我都会得到:
{“错误”:{“状态代码”:400,“名称”:“错误”,“消息”:“需要用户名或电子邮件”,“代码”:“ USERNAME_EMAIL_REQUIRED”}}
我尝试了两种登录方式。首先:
var userDetails = {
"email": "foo%40bar.com",
"password": "test"
}
const requestOptions = {
url: "APIURL/api/Users/login?email="+userDetails.email+"&password="+userDetails.password
};
request.post(requestOptions, function (error, response, body) {
console.log(body);
});
并且:
var userDetails = {
"email": "foo%40bar.com",
"password": "test"
}
const requestOptions = {
url: "https://temp-243314.appspot.com/api/Users/login",
header: {
"email": userDetails.email,
"password": userDetails.password
}
};
request.post(requestOptions, function (error, response, body) {
console.log(body);
});
两者都返回相同的错误。
答案 0 :(得分:1)
;
时,我喜欢它。您的var
声明需要一个lil ;
:D %40
进行网址编码来代替@
5。const request = require('request');
let options = {
uri: 'APIURL/api/Users/login',
method: 'POST',
json: {
"email":"foo@bar.com",
"password":"¡¡¡¡¡¡¡¡UNHACKABLE!!!!!!!!!"
}
};
request(options, function (err, resp, body) {
let isHTTPSuccess;
try {
isHTTPSuccess = resp.statusCode + '';
isHTTPSuccess = isHTTPSuccess[0];
if (isHTTPSuccess === '2'){
isHTTPSuccess = true;
} else {
isHTTPSuccess = false;
}
} catch(parseError){
console.error(parseError);
console.error(err);
return;
}
if (err || !isHTTPSuccess){
console.error(body);
return;
}
console.log('WOWZER, THE CODE ABOVE IS A BIT MUCH NO? ANYWAY... HERE IS THE BODY: ', body);
return;
});
答案 1 :(得分:0)
您的请求应类似于:
var userDetails = {
"email": "foo@bar.com",
"password": "test"
}