1. I built a local server using express and used webpack's proxyTable to forward the online interface.
2. The online interface background is java, and the returned data is in gbk format
3. The client initiates a post request and the data can be returned correctly (in the network)
4. Console.log or rendered in Chinese on the page It’s garbled code, how to solve it
I tried iconv-lite but it didn’t work. I don’t know if it’s written incorrectly
自己写的接口
apiRoutes.post('/hospitallist.xhtml',function(req,res){
res.send(res)
})
会被转到xxx.com/hospitallist.xhtml
我想大声告诉你2017-05-16 13:40:09
Finally, I solved it using the superagent method
var charset = require('superagent-charset');
var superagent = charset(require('superagent'));
function agent(req,res){
superagent.post(url+req.path)
.type('form')
.send(req.body)
.set('Accept', 'application/json')
.charset('gbk')
.end(function (err, sres) {
var html = sres.text;
res.send(html);
});
}
app.post('/list',function(req,res,next){
agent(req,res)
})
PHP中文网2017-05-16 13:40:09
To send data from the background to the front end, add
before instantiating the PrintWriter object response.setCharacterEncoding("GBK");
然后再 PrintWriter writer=response.getWriter();