私はluaとnode jsを初めて使用しています。私が作業しているモバイルアプリケーションをサーバーに接続しようとしています。問題はそれがサーバーに接続していますが、私が通過しようとしているデータが失われたり、サーバーに届かないということです。 私がやっていることに何が間違っているかについてのアイデアはありますか?私のモバイルアプリケーション(luaで書かれた)と私のサーバ(node.jsで書かれた)を接続するには?
this is my lua code to connect to the server
local function store()
local headers = {}
headers["Content-Type"] = "application/x-www-form-urlencoded"
headers["Accept-Language"] = "en-US"
local body = "fname="..fname
local params = {}
params.headers = headers
params.body = body
print(body)
print(headers)
print(params.body)
print(params.headers)
network.request("http://192.168.56.2:8888", "POST", networkListener, params)
end
local function networkListener(event)
if (event.isError) then
print("Network error!")
else
print ("RESPONSE: " .. event.response)
local serializedString = json.decode(event.response)
print(serializedString)
--data = json.decode(serializedString)
--print(serializedString.student[1])
end
end
`
This is the code for the simple server I am trying to send a request to
var express = require('express');
var app = express();
var morgan = require('morgan');
var consolidate = require('consolidate');
var bodyparser = require('body-parser');
var parser = require('luaparse');
////////////////////////////////////////////////////////////////////////////////
app.listen(8888,function() {console.log('Server Running!');});
////////////////////////////////////////////////////////////////////////////////
app.set('views', __dirname + '/views');
app.engine('html', consolidate.nunjucks);
app.use(morgan('dev'));
app.use(bodyparser.urlencoded({ extended: true }));
app.use('/static', express.static(__dirname + '/static'));
////////////////////////////////////////////////////////////////////////////////
app.get('/', function(req, res) {
res.render('index.html');
});
app.post('/', function(req, res) {
var fname = req.fname;
var lname = req.body.lastname;
console.log("it went in");
console.log(req.body.fname);
console.log(req.body);
console.log(req.header);
console.log("nahuman");
res.render('index.html');
});
////////////////////////////////////////////////////////////////////////////////
可能であれば、画像リンクの代わりに質問にコードを含めてください。 – vivek
私の質問を編集し、コードの一部を含める –