[英]Trying to make a get request using NodeJS
我正在嘗試向我的NodeJS服務器端發出獲取請求,但它一直說CERT_UNTRUSTED。 我在客戶端使用的代碼是:
function validateUser(){
var userEmail = $("#userEmail").val();
var userPassword = $("#userPassword").val();
$.ajax({
url: "https://changelog.twvending.net/ValidateUserByName?userName="+userEmail+"&userPassword="+userPassword,
success: function(user){
if (user === "bad user"){
alert("Your credentials are incorrect, please try again");
} else {
if (user.User.PermissionLevel === 3){
localStorage.setItem("permission", "hello");
$("#newEntry").show();
window.location.href = "https://changelog.twvending.net";
}
else {
alert("You do not have permission to make new entries");
window.location.href = "https://changelog.twvending.net";
}
}
},
error: function(xhr,status,error){
}
});
}
在服務器端
app.get('/ValidateUserByName', function (req, res) {
res.setHeader("Access-Control-Allow-Origin", req.getHeader("Origin"));
var userEmail = req.query.userName;
var userPassword = req.query.userPassword;
processInput(userEmail +" logged in");
var request = require('request');
request.get('https://32market.com/32marketpcitest/threesquaremarketrest.svc/ValidateUserByEmailULR?email='+userEmail+'&password='+userPassword,
function (err, resp, body) {
if (err){
processInput ( err )
console.log('Error: ' + err);
return;
}
try {
var user = JSON.parse(body);
res.send(user);
}
catch(err) {
processInput('error logging in: invalid user name or password');
res.send("bad user");
}
});
});
我的問題是我錯過了客戶或服務器不喜歡的東西。 我還應該注意,這是我第一次做這樣的項目。
我的猜測是您沒有要求的或過期的ssl證書來執行您的請求。 可能到32market.com
是否使用https連接? 是你自己的網站嗎?
您可以嘗試添加
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
在您提出要求之前
但這並不完全安全。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.