javascript - nodejs處理post請求回的gbk亂碼怎么處理?
問題描述
1.自己用express搭建的本地服務(wù)器,利用webpack的proxyTable做了線上接口轉(zhuǎn)發(fā)。2.線上接口后臺是java,返回數(shù)據(jù)是gbk格式3.客戶端發(fā)起post請求能正確返回數(shù)據(jù)(network中)4.console.log或者渲染在頁面中中文都是亂碼,請問怎么解決
試了下iconv-lite不奏效,不知道是不是寫的不對
自己寫的接口apiRoutes.post(’/hospitallist.xhtml’,function(req,res){ res.send(res)})會被轉(zhuǎn)到xxx.com/hospitallist.xhtml
問題解答
回答1:最后還是用superagent的方法解決了
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)})回答2:
res.charset = ’gbk’;res.send(’some thing’);回答3:
后臺發(fā)送數(shù)據(jù)到前端,在實例化PrintWriter對象前加上
response.setCharacterEncoding('GBK');然后再 PrintWriter writer=response.getWriter();
相關(guān)文章:
1. macos - 如何徹底刪除mac自帶的apache和php2. javascript - sublime快鍵鍵問題3. docker 17.03 怎么配置 registry mirror ?4. DADB.class.php文件的代碼怎么寫5. javascript - immutable配合react提升性能?6. css - 寫頁面遇到個布局問題,求大佬們幫解答,在線等,急!~7. mysql事務(wù)回滾定位8. javascript - html5多個label中其中一個觸發(fā)change,如何判斷是哪一個出發(fā)了change9. 實現(xiàn)bing搜索工具urlAPI提交10. css - 移動端字體設(shè)置問題

網(wǎng)公網(wǎng)安備