我正在尝试向我的NOde JS Express服务器发帖。这是服务器代码:
var http = require('http');
var express=require('express');
var app=express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
var mysql=require('mysql');
app.post('/ignitionInput',function(req, res){
var jsonRecieved=req.body;
var accountId=jsonRecieved.AccountId;
var deviceId=jsonRecieved.DeviceId;
var latitude=jsonRecieved.Latitude;
var longitude=jsonRecieved.Longitude;
var address=jsonRecieved.Address;
var phoneNumber=jsonRecieved.PhoneNumber;
var vehicleNumber=jsonRecieved.VehicleNumber;
console.log(jsonRecieved);
connectionpool.getConnection(function(err, connection) {
//Some db operations
});
});
当我尝试使用POSTMAN发出请求时,它会发送正确的正文但是当我使用TELERIK FIDDLER发出相同的请求时,它会收到空的身体。
我在下面发布JSON:
{
"AccountId":"abhinay",
"DeviceId":"00000000000000000",
"Latitude":"28.607835",
"Longitude":"77.2879133",
"Address":"Noida Link Road, Pandav Nagar, New Delhi, Delhi 110091, India",
"PhoneNumber":"23456789066556",
"VehicleNumber":"DL3C AK 234567"
}
HTTP标头:
Fiddler:
User-Agent: Fiddler
Host: localhost:9999
Content-Length: 276
Content-Type: "application/json"
Cache-Control: no-cache
邮差:
Connection → keep-alive
Content-Length → 177
Content-Type → application/json; charset=utf-8
Date → Sun, 08 Feb 2015 10:53:55 GMT
X-Powered-By → Express
注意:我已经提到过Content-Type:" application / json"在HTTP HEADER中
为什么会这样?任何想法??