Proxy works for POST that body is wrong
The body received by the agent's interface is an object The object's contents are: { '{"startTime":"2017-06-21 00:00:00","endTime":"2017-06-21 23:59:59"}':"" } What we want to achieve is body content :
{"startTime":"2017-06-21 00:00:00","endTime":"2017-06-21 23:59:59"}
version: "express": "^4.15.3", "express-http-proxy": "^1.0.4",
I have the same problem. My proxy is:
var express = require('express');
var router = express.Router();
var bodyParser = require("body-parser");
var proxy = require("express-http-proxy");
router.use('/api', function(req, res, next) {
console.log(req.body);
next();
});
router.use('/api', proxy('db:3000'));
and my server is
var express = require('express');
var router = express.Router();
var bodyParser = require("body-parser");
router.post('/', function(req, res, next) {
console.log(req.body);
}
The output of my proxy is:
{ key: 'value' }
and the output of my server is
{ '{"key":"value"}': '' }
Both outputs should be same. How to fix this? When I send my request with Postman, it works. The problem is with jQuery.post().
[email protected] [email protected] [email protected] [email protected]
I found the difference and the problem. Postman sends by default with Conent-Type: 'application/x-www-form-urlencoded'. jQuery sends by default with Content-Type: 'application/x-www-form-urlencoded; charset=UTF-8'. When I change Content-Type to 'application/x-www-form-urlencoded', it works. That means, that express-http-proxy has a problem with Content-Type: 'application/x-www-form-urlencoded; charset=UTF-8'