【发布时间】:2016-06-20 19:33:52
【问题描述】:
我几乎准备好部署应用程序,但遇到了障碍。
我有一个 nodejs 应用程序 (http://sslscanner-ssldecoder.azurewebsites.net/decoder/)
当我在本地机器上运行时,一切正常。 但是当我(在 Azure 上)部署它时,AJAX 调用不会发送正文(我认为)。
这里是 jQuery 调用:
$("#decoderSubmit").on('click', function() {
var body = $('#csr').val();
var csr;
decode(body, csr);
});
function decode(body, csr) {
$.ajax({
type: 'POST',
url: '/api/decoder',
data: {
body: body,
csr: csr
},
dataType: 'JSON',
timeout: 4500,
success: callback,
error: fail
});
function callback(data) {
var csrBody = data.slice(0, 20);
var certBody = data.slice(0, 12);
if (!csr) {
console.log(certBody);
}
if (csr) {
console.log(csrBody);
}
}
function fail(request, status, err) {
console.log(err);
}
}
这里是 NodeJS 端点(/api/decoder):
router.route('/decoder')
.post(function(req, res) {
let body = req.body.body;
let csr = req.body.csr;
decode(body, csr, function(err, result) {
if (err)
throw err;
res.json(result);
});
function decode(data, type, callback) {
if (type == 'true') {
let inFile = randCertFileName();
var result;
fs.writeFile(inFile, data, function(err) { // Write the cert to a file
if (err) {
console.error("Error writing certificate: " + err);
return callback(err);
}
});
execute('openssl req -in ' + inFile + ' -text', function(out) { // Execute the certutil dump command
result = out;
var hash = crypto.createHash('sha1').update(data).digest('hex');
result = result.concat('\n', 'sha1:', hash);
hash = crypto.createHash('md5').update(data).digest('hex');
result = result.concat('\n', 'md5:', hash);
fs.unlink(inFile); // Delete the certificate file
return callback(null, result);
});
} else if (type == 'false') {
let inFile = randCertFileName(); // Get a random filename for incoming cert
var result;
fs.writeFile(inFile, data, function(err) { // Write the cert to a file
if (err) {
console.error("Error writing certificate: " + err);
return callback(err);
}
});
execute('openssl x509 -in ' + inFile + ' -text', function(out) { // Execute the certutil dump command
result = out;
fs.unlink(inFile); // Delete the certificate file
return callback(null, result);
});
}
}
});
在比较服务器上调用的标头和 localhost 上的调用时,我注意到的一件事是添加了这个额外的标头: "X-Powered-By:ASP.NET"
如果这是问题所在,您能帮我理解如何覆盖它吗?
我们将不胜感激。谢谢。
【问题讨论】:
-
会发生什么?您在控制台中看到了什么?
-
“console.log(certBody)”行没有返回任何内容。它是空的。而我的其余代码取决于调用的响应,所以什么也没有发生。
-
您是否尝试过注释掉“执行”行并使用虚拟对象调用回调?我的第一个怀疑是衍生任务。
-
我有另一个端点,它几乎与这个端点完全相同,它使用该命令不会失败。但我会尝试并回复你。
-
它说它被取消了。我将它设置为返回一个空字符串。