JQuery Ajax HTTPS -Aufruf gibt Err_insecure_Response anJquery

JQuery-Programmierung
Anonymous
 JQuery Ajax HTTPS -Aufruf gibt Err_insecure_Response an

Post by Anonymous »

Ich versuche, einen HTTPS -CORS AJAX -Anruf von JQuery zu einem Node.js -Prozess zu tätigen. Wenn jedoch der Anruf getätigt wird, beschwert sich Chrome in der Konsole: Optionen https: // localhost/net :: err_inecure_response . Also habe ich das Cert in Chrome importiert. Ich kann das Zertifikat in der Registerkarte "Zertifikate" von Chrome unter Behörden verwalten. Aber es schlägt immer noch fehl, wenn ich den Ajax -Anruf versuche. < /P>
So habe ich den privaten Schlüssel gemacht:

Code: Select all

openssl genrsa -out domain.key 4096

Jetzt das Zertifikat:

Code: Select all

openssl req -x509 -sha512 -nodes -newkey rsa:4096 -keyout domain.key -out domain.crt
< /code>
Für den gebräuchlichen Namen stelle ich die IP -Adresse des Computers ein, sodass Chrome sich nicht über eine URL -Fehlanpassung beschweren würde. < /p>
Hier ist die HTML -Seite.

BlackBox










 Welcome to BlackBox
username

password












< /code>
Dies ist das JavaScript, das mit dem HTML einhergeht. < /p>
 $(document).ready(function() {
$('#loginbtn').click(clickLogin);
function clickLogin() {
var username = $('#username').val();
var password = $('#password').val();
if(password == '' || username == '') {
$(".out").html("Empty username or password");
} else {
$.ajax({
type: "PUT",
url: "https://localhost/",
contentType: "application/json",
data: JSON.stringify({
username: username,
password: password,
}),
dataType: "text",
})
}
};
});
< /code>
Und schließlich ist hier der Knotenprozess, der sowohl HTML als auch JavaScript dient und die AJAX -Anrufe empfangen soll.  < /p>
const fs = require("fs");
const http = require('http');
const https = require('https');

var loginPage = fs.readFileSync('login.html');
var loginPageJs = fs.readFileSync('login.js');
var jquery = fs.readFileSync('jquery-1.11.2.js');
var bootstrap = fs.readFileSync('bootstrap-3.3.4-dist/js/bootstrap.min.js')

var options = {
key: fs.readFileSync('domain.key'),
cert: fs.readFileSync('domain.crt')
};

http.createServer(function(req, res) {
res.writeHead(301, {Location: 'https:192.168.1.58/'})
res.end();
}).listen(80);

https.createServer(options, function(req, res) {

if(req.method === 'GET' && req.url === '/') {
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.write(loginPage);
res.end();
} else if(req.method === 'GET' && req.url === '/login.js') {
res.writeHead(200, "OK", {'Content-Type': 'application/javascript'});
res.write(loginPageJs);
res.end();
} else if(req.method === 'GET' && req.url === '/jquery-1.11.2.js') {
res.writeHead(200, "OK", {'Content-Type': 'application/javascript'});
res.write(jquery);
res.end();
} else if(req.method === 'GET' && req.url === '/bootstrap-3.3.4-     dist/js/bootstrap.min.js') {
res.writeHead(200, "OK", {'Content-Type': 'application/javascript'});
res.write(bootstrap);
res.end();
} else if(req.method === "OPTIONS" && req.url === '/') {
res.writeHead(204, "No Content", {
"access-control-allow-origin": origin,
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
"access-control-allow-headers": "content-type, accept",
"access-control-max-age": 10,
"content-length": 0
});

var requestBodyBuffer = [];

req.on("data", function(chunk) {
requestBodyBuffer.push(chunk);
})

req.on("end", function() {
var requestBody = requestBodyBuffer.join("");
var obj = JSON.parse(requestBody);
if(obj.hasOwnProperty('username') && obj.hasOwnProperty('password'))  {
console.log(obj.username);
console.log(obj.password);
}
})
}

}).listen(443);

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post