fly icon indicating copy to clipboard operation
fly copied to clipboard

响应拦截器收到加密的数据返回走err回调去了

Open Sunfloweee opened this issue 5 years ago • 1 comments

正常的数据返回的话可以走到 response 返回, 然后进行数据处理. 但是后台返回了加密的数据, 明明是200 请求成功, 在响应拦截的时候先到了err 的回调

Sunfloweee avatar May 17 '19 09:05 Sunfloweee

原因找到了. fly默认对数据结果的返回进行了判断, 如果是非对象的情况下, 进行 JSON.parse() , 这就是问题的根源了. 后台返回的加密数据根本不能直接就进行解析, 需要通过自身定义的密钥才可以编译出来, 那么我们绕过源码的解析就好了 .

engine.onload = function () { console.log(engine) try { // The xhr of IE9 has not response field var response = engine.response || engine.responseText; if (response && options.parseJson && (engine.getResponseHeader(contentType) || "").indexOf("json") !== -1 // Some third engine implementation may transform the response text to json object automatically, // so we should test the type of response before transforming it && !utils.isObject(response)) { response = JSON.parse(response); } ....

修改为 response = response || JSON.parse(response); 即可.

Sunfloweee avatar May 17 '19 10:05 Sunfloweee