Answer the question
In order to leave comments, you need to log in
Why is the body of the POST request not coming?
I'm trying to write a layer to proxy all requests to the server.
On the server
In a router in a switch I disassemble methods.app.use('/api/*', router);
case 'GET':
request
.get(config.apiUrl + req.originalUrl)
.set('Content-Type', req.headers['content-type'] || 'application/json')
.set('Authorization', req.headers['authorization'])
.end((err, response) => {
if(err) {
if(err.code === 'ECONNREFUSED') {
res.status(500).send(err);
return;
}
res.status(err.status).send(err.error)
return;
}
res.status(response.status).send(response.body)
});
break;
case 'POST':
request
.post(config.apiUrl + req.originalUrl)
.send(req.body)
.set('Content-Type', req.headers['content-type'] || 'application/json')
.set('Authorization', req.headers['authorization'])
.end((err, response) => {
if(err) {
if(err.code === 'ECONNREFUSED') {
res.status(500).send(err);
return;
}
res.status(err.status).send(err.error)
return;
}
res.status(response.status).send(response.body)
});
console.log("Method POST", req.params, req.query, req.body);
break;
fetch('/api/сфдд', {
method: 'post',
headers: {
'Authorization': access_token,
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
});
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
authorization:Bearer c1e86a69-70ab-4bb2-88d8-5265b5e52f82
Cache-Control:max-age=0
Connection:keep-alive
content-type:application/json
Cookie:_lang=en; _ga=GA1.1.1086216394.1446999795
Host:localhost:3000
If-None-Match:W/"148-KV8tQb406/euCb07gsnbnQ"
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Response Headersview source
Connection:keep-alive
Date:Mon, 09 Nov 2015 09:23:57 GMT
ETag:W/"148-KV8tQb406/euCb07gsnbnQ"
X-Powered-By:Express
Host: localhost:3000
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json
Authorization: Bearer c1e86a69-70ab-4bb2-88d8-5265b5e52f82
Referer: http://localhost:3000/
Origin: http://localhost:3000
Connection: keep-alive
Connection: keep-alive
Content-Length: 328
Content-Type: application/json; charset=utf-8
Date: Mon, 09 Nov 2015 09:35:13 GMT
Etag: W/"148-KV8tQb406/euCb07gsnbnQ"
Vary: Accept-Encoding
X-Powered-By: Express
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question