前端是vue,后端是java,現(xiàn)在后端接口是gbk的,前端如何改成能夠正常調(diào)用接口?尤其是請(qǐng)求參數(shù)如何轉(zhuǎn)gbk?網(wǎng)上找到了這段1、對(duì)傳入的GBK字符串,要用數(shù)據(jù)流接收,具體到angularjs中,$http 請(qǐng)求中需要覆蓋參數(shù)responseType , responseType: "arraybuffer",$http({ method: "POST", responseType: "arraybuffer", url: "restcater/cenchain/findCenChain", data: branchlist})2、解析var x = new Uint8Array(resp.data);var str =new TextDecoder('gbk').decode(x);已經(jīng)正常識(shí)別了。/////////////////////////////////////////////////////////3、UTF-8提交的數(shù)據(jù)轉(zhuǎn)為GBK,要引用第三方JS庫https://github.com/inexorabletash/text-encoding<script> // var TextEncoderOrg = window.TextEncoder; // ... and deactivate it, to make sure only the polyfill encoder script that follows will be used window.TextEncoder = null;</script><script src="lib/text-encoding/encoding-indexes.js"></script><script src="lib/text-encoding/encoding.js"></script> //獲取GBk編碼的int8數(shù)組 var uint8array = new TextEncoder("gbk",{ NONSTANDARD_allowLegacyEncoding: true }).encode(string); // 放入blob中準(zhǔn)備上傳 var blob=new Blob([uint8array],{type:"text/plain"});但實(shí)際使用UTF-8提交的數(shù)據(jù)轉(zhuǎn)為GBK這個(gè)似乎沒有用啊,轉(zhuǎn)出來得到的uint8array 是個(gè)數(shù)組,調(diào)用接口參數(shù)還需要進(jìn)行des加密,需要變成字符串,這又要怎么做呢?
js請(qǐng)求gbk接口的問題
慕容3067478
2019-03-14 14:19:37