我正在使用cordova文件传输插件版本1.3.0从我的Android设备上的Web Api服务器下载文件; 我正在尝试发送标头(即Accept和一些自定义标头),但是如果 我用嗅探器(比如wireshark)检查服务器上的请求,我的 标题不存在。
我正在使用phonegap build(cli 5.2.2)来构建apk; 我的设备是三星GT-S7500(Android 2.3.6姜饼); 在config.xml中我设置了白名单和包含插件(我试过指定版本号(1.3.0)而没有它);
这是我的代码(在DeviceReady事件处理程序中调用)
var fileTransfer = new FileTransfer();
fileTransfer.download(attachUri, fileURL,
function (entry) {
debug.log("ERROR","download complete: " + entry.toURL());
window.open(entry.toNativeURL(), '_blank', 'location=no,closebuttoncaption=Close,enableViewportScale=yes');
},
function (error) {
alert("Error:" + error);
debug.log("ERROR",error);
}),
false,
{
headers:{
"Accept":"application/octet-stream",
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
};
这是web api服务器收到的标题
Connection: Keep-Alive
Accept-Encoding: gzip
Host: 192.168.0.10
User-Agent: Dalvik/1.4.0
User-Agent: (Linux; U; Android 2.3.6; GT-S7500 Build/GINGERBREAD)
在Github上,类似于此的错误似乎已在1.3.0版本上得到修复。但它在我的情况下不起作用。
有任何帮助吗?
编辑:这是我的config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.AsxMobApp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>AsxMobApp</name>
<description>
AsxMobApp
</description>
<author>
AsxMobApp Team
</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="10" />
<preference name="android-installLocation" value="auto" />
<preference name="AndroidPersistentFileLocation" value="Internal" />
<gap:plugin name="org.apache.cordova.battery-status" source="npm" />
<gap:plugin name="org.apache.cordova.camera" source="pgb" version="0.3.6" />
<gap:plugin name="org.apache.cordova.media-capture" source="npm" />
<gap:plugin name="org.apache.cordova.console" source="npm" />
<gap:plugin name="org.apache.cordova.contacts" source="npm" />
<gap:plugin name="org.apache.cordova.device" source="npm" />
<gap:plugin name="org.apache.cordova.device-motion" source="npm" />
<gap:plugin name="org.apache.cordova.device-orientation" source="npm" />
<gap:plugin name="org.apache.cordova.dialogs" source="npm" />
<gap:plugin name="org.apache.cordova.geolocation" source="npm" />
<gap:plugin name="org.apache.cordova.globalization" source="npm" />
<gap:plugin name="org.apache.cordova.inappbrowser" source="npm" />
<gap:plugin name="org.apache.cordova.media" source="npm" />
<gap:plugin name="org.apache.cordova.network-information" source="npm" version="0.2.3" />
<gap:plugin name="org.apache.cordova.splashscreen" source="npm" />
<gap:plugin name="org.apache.cordova.vibration" source="npm" />
<gap:plugin name="cordova-plugin-file" />
<!-- file-transfer: questo plugin permette di scaricare in locale dei file da specifici url -->
<gap:plugin name="cordova-plugin-file-transfer" source="npm" />
<!-- whitelist: questo plugin permette di configurare i domini a cui l'applicazione può accedere via http, https ecc.
serve per far funzionare il plugin filetransfer che permette di scaricare in locale dei file da un determinato url (nel nostro caso gli allegati di una mail) -->
<gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source = "npm"/>
<icon src="icon.png" />
<icon gap:platform="android" gap:qualifier="ldpi" src="www/res/icon/android/icon-36-ldpi.png" />
<icon gap:platform="android" gap:qualifier="mdpi" src="www/res/icon/android/icon-48-mdpi.png" />
<icon gap:platform="android" gap:qualifier="hdpi" src="www/res/icon/android/icon-72-hdpi.png" />
<icon gap:platform="android" gap:qualifier="xhdpi" src="www/res/icon/android/icon-96-xhdpi.png" />
<icon gap:platform="blackberry" src="www/res/icon/blackberry/icon-80.png" />
<icon gap:platform="blackberry" gap:state="hover" src="www/res/icon/blackberry/icon-80.png" />
<icon gap:platform="ios" height="57" src="www/res/icon/ios/icon-57.png" width="57" />
<icon gap:platform="ios" height="72" src="www/res/icon/ios/icon-72.png" width="72" />
<icon gap:platform="ios" height="114" src="www/res/icon/ios/icon-57-2x.png" width="114" />
<icon gap:platform="ios" height="144" src="www/res/icon/ios/icon-72-2x.png" width="144" />
<icon gap:platform="webos" src="www/res/icon/webos/icon-64.png" />
<icon gap:platform="winphone" src="www/res/icon/windows-phone/icon-48.png" />
<icon gap:platform="winphone" gap:role="background" src="www/res/icon/windows-phone/icon-173-tile.png" />
<gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="www/res/screen/android/screen-ldpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="www/res/screen/android/screen-mdpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="www/res/screen/android/screen-hdpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="www/res/screen/android/screen-xhdpi-portrait.png" />
<gap:splash gap:platform="blackberry" src="www/res/screen/blackberry/screen-225.png" />
<gap:splash gap:platform="ios" height="480" src="www/res/screen/ios/screen-iphone-portrait.png" width="320" />
<gap:splash gap:platform="ios" height="960" src="www/res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
<gap:splash gap:platform="ios" height="1136" src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" width="640" />
<gap:splash gap:platform="ios" height="1024" src="www/res/screen/ios/screen-ipad-portrait.png" width="768" />
<gap:splash gap:platform="ios" height="768" src="www/res/screen/ios/screen-ipad-landscape.png" width="1024" />
<gap:splash gap:platform="winphone" src="www/res/screen/windows-phone/screen-portrait.jpg" />
<!-- allow-navigation questa configurazione dice al plugin whitelist che tutti i domini possono essere contattati; in questo modo si riesce a far funzionare il plugin filetransfer che permette di scaricare in locale un file da un URL (nel nostro caso per il download in locale degli allegati -->
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<engine name="android" spec="~4.1.1" />
</widget>
答案 0 :(得分:0)
@elena,
从Cordova 5.0.0开始,您需要使用whitelist
系统。
whitelist system
有5个部分,即使是经验丰富的开发人员也很难。
您需要在1)config.xml
中添加一个部分,并为您的2 index.html
添加一行。
1)添加到您的config.xml
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->
2)添加到你的index.html
<meta http-equiv="Content-Security-Policy"
content="default-src *;
style-src 'self' 'unsafe-inline' 'unsafe-eval';
script-src 'self' 'unsafe-inline' 'unsafe-eval';">
请参阅以下链接以帮助您保护自己的应用
HOW TO apply the Cordova/Phonegap the whitelist system
最好的运气
答案 1 :(得分:0)
好。
我已删除,图标,飞溅,某些偏好等。这是你可以放回去的东西。
cli-5.2.0
。14
。这是因为你正在使用姜饼。编译器应该设置为该值,但我想确保您的设备正常工作。file-transfer
; file-transfer
安装所需的file
版本。 (file
在评论中,以防万一。)如果你遇到问题,我将再续半小时。whitelist
插件;确保在CSP
。index.html
请在过去60天内阅读Phonegap Build blog,并预计在接下来的30天内会有更多更改。
阅读粗线 Top Mistakes by Developers new to Cordova/Phonegap
HOW TO apply the Cordova/Phonegap the whitelist system
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.AsxMobApp"
version="1.0.0"
xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0">
<name>AsxMobApp</name>
<description>AsxMobApp</description>
<author>AsxMobApp Team</author>
<preference name="phonegap-version" value="cli-5.2.0" />
<preference name="android-minSdkVersion" value="14" />
<plugin name="cordova-plugin-camera" source="npm" spec="1.2.0" />
<plugin name="cordova-plugin-network-information" source="npm" spec="1.0.1" />
<!-- <plugin name="cordova-plugin-file" source="npm" spec="2.1.0" /> -->
<!-- file-transfer: questo plugin permette di scaricare in locale dei file da specifici url -->
<plugin name="cordova-plugin-file-transfer" source="npm" spec="1.2.0" />
<!-- whitelist: questo plugin permette di configurare i domini a cui l'applicazione può accedere via http, https ecc.
serve per far funzionare il plugin filetransfer che permette di scaricare in locale dei file da un determinato url (nel nostro caso gli allegati di una mail) -->
<plugin name="cordova-plugin-whitelist" source="npm" spec="1.1.0" />
<!-- allow-navigation questa configurazione dice al plugin whitelist che tutti i domini possono essere contattati; in questo modo si riesce a far funzionare il plugin filetransfer che permette di scaricare in locale un file da un URL (nel nostro caso per il download in locale degli allegati -->
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->
</widget>