已修复。我们所做的是在调用(成功)中捕获在服务器上创建会话的 cookie。我们将 cookie 保存在本地,然后将其发送到打开 PDF 插件,该插件将 cookie 添加到制作原生部分的调用中。
JS部分:
success: _.bind(function(data, textStatus, request){
var header = request.getAllResponseHeaders();
console.log("header: "+header);
var match = header.match(/(Set-Cookie|set-cookie|Set-cookie): (.+?);/);
console.log("match: "+match);
if(match!==undefined && match!==null && match.length>=3){
console.log("CON COOKIE");
console.log("COOKIE: "+match[2]);
localStorage.setItem("miCookie",match[2]);
}
},this),
插件调用
function callShowPdfPluginAndroid( param ){
require(['utils'], function(utils) {
utils.showLoading();
return cordova.exec( function(){utils.hideLoading();},
function(error){utils.hideLoading();nativePluginErrorHandler(error);},
"NativeBridgeAndroid",
"ShowPdf",
[param,localStorage.getItem("miCookie")]);
});
}
本地人:
URL u = new URL(params[0]);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setRequestProperty("Cookie",cookie);
c.setDoOutput(true);
c.connect();