微信扫描二维码总是用默认浏览器打开,无法下载任何东西。怎么办呢?
微信识别到打开为pdf 时,会自动给跳转至浏览器,所以解决方法就是服务器判断请求端为微信时,返回头部添加
Content-type:application/pdf
Content-Disposition:attachment;filename='downloaded.pdf'
不是微信发起的请求则为真实网页。
搞定!下面是jsp。
<%@ page language="java" import="java.util.*,java.io.*"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
</head>
<%
String userAgent=request.getHeader("user-agent").toLowerCase();
if(userAgent.indexOf("micromessenger")>-1){
// request.setAttribute("isWx","1");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename='downloaded.pdf'");
}else{
//request.setAttribute("isWx","0");
}
%>
<body>
ddddddd
</body>
</html>
微信扫描二维码总是用默认浏览器打开,无法下载任何东西。怎么办呢?
微信识别到打开为pdf 时,会自动给跳转至浏览器,所以解决方法就是服务器判断请求端为微信时,返回头部添加
Content-type:application/pdf
Content-Disposition:attachment;filename='downloaded.pdf'
不是微信发起的请求则为真实网页。
搞定!下面是jsp。
<%@ page language="java" import="java.util.*,java.io.*"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
</head>
<%
String userAgent=request.getHeader("user-agent").toLowerCase();
if(userAgent.indexOf("micromessenger")>-1){
// request.setAttribute("isWx","1");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename='downloaded.pdf'");
}else{
//request.setAttribute("isWx","0");
}
%>
<body>
ddddddd
</body>
</html>