1
我遇到了一个有线问题,如果以这种方式提交,那么相同的确切代码(访问AWS Api Gateway)运行得很好:node app.js,但产生307从Node/Express应用程序提交时,重定向。如何从节点Web应用程序正确访问AWS Api网关
这里是“独立”的单个文件节点程序(app.js):
var http = require("https");
var options = {
"method": "POST",
"hostname": "ipzjnsvxnd.execute-api.us-west-2.amazonaws.com",
"port": null,
"path": "/DEV/execution",
"headers": {
"cache-control": "no-cache",
"postman-token": "b929e970-fe22-0f4f-e659-117890fda955"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function() {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write("{\n \"input\": \"{ \\\"account_key\\\": \\\"9990\\\", \\\"acc1\\\": \\\"1235813\\\", \\\"acc2\\\": \\\"13711\\\",\\\"amount\\\": \\\"1000.00\\\", \\\"city\\\": \\\"BrandonTown\\\" }\",\n \"name\": \"RequiredUniqueValueGoesHere19090\",\n \"stateMachineArn\": \"arn:aws:states:us-west-2:217465658899:stateMachine:FICO_StateMachine3\"\n}");
req.end();
这里是相同的代码,作为节点/快速的Web应用程序的一部分:
提交时module.exports = function(app) {
var querystring = require('querystring');
var http = require('http');
http.post = require('http-post');
app.get('*', function(req, res) {
res.sendfile('./public/index.html');
});
app.post("/customerinfo", function(req, res) {
var options = {
"method": "POST",
"hostname": "ipzjnsvxnd.execute-api.us-west-2.amazonaws.com",
"path": "/DEV/execution",
"headers": {
"cache-control": "no-cache",
"postman-token": "b929e970-fe22-0f4f-e659-117890fda955"
}
};
var req1 = http.request(options, function (res1) {
var chunks = [];
res1.on("data", function (chunk) {
chunks.push(chunk);
});
res1.on("end", function() {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req1.write("{\n \"input\": \"{ \\\"account_key\\\": \\\"9990\\\", \\\"acc1\\\": \\\"1235813\\\", \\\"acc2\\\": \\\"13711\\\",\\\"amount\\\": \\\"1000.00\\\", \\\"city\\\": \\\"BrandonTown\\\" }\",\n \"name\": \"RequiredUniqueValueGoesHere1239091\",\n \"stateMachineArn\": \"arn:aws:states:us-west-2:217465658899:stateMachine:FICO_StateMachine3\"\n}");
req1.end();
});
};
第一个正常工作:节点app.js 第二个回报:
<html>
<head><title>307 Temporary Redirect</title></head>
<body bgcolor="white">
<center><h1>307 Temporary Redirect</h1></center>
<hr><center>CloudFront</center>
</body>
</html>
<html>
<head><title>307 Temporary Redirect</title></head>
<body bgcolor="white">
<center><h1>307 Temporary Redirect</h1></center>
<hr><center>CloudFront</center>
</body>
</html>
<html>
<head><title>307 Temporary Redirect</title></head>
您需要更改代码'HTTP =需要(“HTTP”)'到'http = require('https')'在快速应用程序内。 –
这个效果很好 - 谢谢。如果您将此作为解决方案发布,我很乐意接受。 –
很高兴工作。添加了我的答案! –