0
私のAngular投稿要求の本文は私のサーバーでは空です。私のクライアントアプリケーションからのPOSTリクエストは、次のとおりです。Angular投稿要求の本文が空です
var data = {
Stime: '+this.Stime+',
Etime: '+this.Etime+',
eAMPM: '+this.eAMPM+',
sAMPM: '+this.sAMPM+',
id: '+this.id+',
activity: '+this.activity+',
auto_insert: '+this.auto_insert+',
yearmonthday: '+this.yearmonthday+',
color1: '+this.c+'
}
this.$http({
method: 'POST',
url: 'http://localhost:3000/operation',
data: JSON.stringify(data)
})
私は、私はちょうど非常に長いクエリ文字列を持っていたこのポストの要求を使用してみました、これはうまくデータを渡す前に。しかし、私は今私のコードを浄化しています、そして、この方法では動作しません。私は自分のサーバー上で :
サーバー側でもapp.post('/operation', function(req,res){
console.log(req.body); //prints {}
res.send("inserted");
});
私はapp.post(...) {}
インサイド
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
multer = require('multer'),
jsonParser = bodyParser.json()
app.use(jsonParser)
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
はあなたを持っています角$ httpを使って試しましたか? https://docs.angularjs.org/api/ng/service/$http。 '$ http.post( 'http:// localhost:3000/operation'、data)'を使用しているように、データオブジェクト をアセンブルしますか? –