嵌入式安卓附件下载始终为0kb

附件在安卓机上无法下载,在ios上可以下载,直接用浏览器也可以下载。
前端代码:

    window.location.href = G_CTX_PATH + "/mobile/xxxx/downloadFile?attachmentId="+attachmentId+"&userToken="+encodeURIComponent(encodeURIComponent(userToken));

后端是通过java io 去读取响应的。
抓包看的,数据正常响应回来,但是安卓机保存后就0kb。

我们前端代码是 html5嵌入在别人的app里面的,点击附件下载时。app就代码本机浏览器去访问链接。

感觉应该是前端处理问题,求大佬告知。

前段换成这种方式了
function downloadFiles(attachmentId,name){
//var TK = $("#TK").val();
//"&TK="+TK+
var userToken =$("#userToken").val();
//window.location.href =G_CTX_PATH + "/mobile/common/downloadFile?attachmentId="+attachmentId+"&userToken="+encodeURIComponent(encodeURIComponent(userToken));
openDownloadDialog(G_CTX_PATH + "/xxxx/common/downloadFile?attachmentId="+attachmentId+"&userToken="+encodeURIComponent(encodeURIComponent(userToken)),name);
};

function openDownloadDialog(url, saveName)
{
if(typeof url == 'object' && url instanceof Blob)
{
url = URL.createObjectURL(url); // 创建blob地址
}
var aLink = document.createElement('a');
aLink.href = url;
aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
var event;
if(window.MouseEvent) event = new MouseEvent('click');
else
{
event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
}
aLink.dispatchEvent(event);
};

补充:报文信息
第一次请求
GET http://xxx.xxx.xxx.xxx:9088/xxxxx/xxxx/common/downloadFile?attachmentId=xxxx&userToken=xxxxx HTTP/1.1
Host: xxx.xxx.xxxx.xxx:9088
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 9; HWI-AL00 Build/HUAWEIHWI-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh-Hans-CN,zh-Hant-HK;q=0.8,en-US;q=0.6
Cookie: JSESSIONID=xxxxxxx

HTTP/1.1 200 OK
Content-Disposition: attachment; filename="xxxx.jpg"
Content-Type: application/octet-stream;charset=UTF-8
Content-Length: 1066724
Date: Wed, 30 Oct 2019 02:20:51 GMT
Server: OWN/8.5

第二次
GET http://xxx.xxx.xxx.xxx:9088/xxxx/mobile/xxxx/downloadFile?attachmentId=xxx&userToken=xxxx HTTP/1.1
Host: xxx.xxx.xxx.xxx:9088
Connection: Keep-Alive
Accept-Charset: utf-8
Accept-Encoding: utf-8
Accept-Language: zh-CN
User-Agent: Mozilla/5.0 (Linux; Android 9; HWI-AL00 Build/HUAWEIHWI-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36
Range: bytes=0-
Referer: ext:/lp:home
Accept: multipart/mixed,text/html,image/png,image/jpeg,image/gif,image/x-xbitmap,application/vnd.oma.dd+xml,*/*
Cookie: JSESSIONID=xxxx

HTTP/1.1 200 OK
Date: Wed, 30 Oct 2019 02:21:03 GMT
Server: OWN/8.5
Content-Length: 48

Terminate because of csrf!http://xxx.xxxx.xxx.xxx

===========================================分割线
问题已经解决了,前段换了上面的第二种js
后台的话被拦截器拦截了,有csrf防攻击拦截器,
本来打算优雅点解决,通过js置空referer但是前端功底太弱,没办反只能后台改了拦截器降低拦截力度,只拦截post请求。帖子结了,分给一楼捧场的小伙伴了。

1个回答

看下android是不是用了第三方“加速浏览器”之类,发出去的cookie referer useragent是否异常,是否被附加了别的东西
网络是否异常

Blueters
半生风雪沾青衣 csrf 好像是被这个拦截了,这个要怎么特殊处理一下吗,求指点
5 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问