Android XMLHttpRequest请求失败

Android XMLHttpRequest请求失败,android,eclipse,xmlhttprequest,Android,Eclipse,Xmlhttprequest,我对Android上使用Eclipse的XMLHttpRequest有问题 如果我在连接的设备上构建并运行应用程序,我不会收到任何错误,但是当我构建apk并在设备上安装时,我会收到一个错误,因此我缺少权限或其他信息。谢谢你的帮助 var send = function() { a = new XMLHttpRequest(); a.open((type.toLowerCase()==="post")?"POST":"GET",self.

我对Android上使用Eclipse的XMLHttpRequest有问题

如果我在连接的设备上构建并运行应用程序,我不会收到任何错误,但是当我构建apk并在设备上安装时,我会收到一个错误,因此我缺少权限或其他信息。谢谢你的帮助

      var send = function() {
            a = new XMLHttpRequest();
            a.open((type.toLowerCase()==="post")?"POST":"GET",self._prepareUrl(url),true);//+'&username='+data.userid,true);
            a.onreadystatechange = rsc;
            a.timeout = 50000;
            setTimeout(function () {     /* vs. a.timeout */
                if (a.readyState < 4) {
                    a.abort();
                }
            }, 50000);        

            a.ontimeout = to;
            a.onerror = err;
            a.onabort = errAbort;

            a.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");
            a.send(resData);
        };
我得到的信息是:

状态=0 状态=4 无回应文本

那么请求被中止了,但为什么呢?我必须在下面的文件中缺少一些内容,因为当我通过eclipse运行应用程序时,它确实可以工作,默认情况下,它必须允许某些内容,但当apk构建并安装在设备上时,我会在安装时看到allow permissions info(允许权限信息)屏幕,而在通过eclipse运行时,该屏幕不会出现

舱单是:

<?xml version='1.0' encoding='utf-8'?>
<manifest 
android:versionCode="5" 
android:versionName="1.3" 
package="XXXXX" 
android:windowSoftInputMode="adjustPan"
xmlns:android="http://schemas.android.com/apk/res/android">

<supports-screens 
    android:anyDensity="true" 
    android:largeScreens="true" 
    android:normalScreens="true" 
    android:resizeable="true" 
    android:smallScreens="true" 
    android:xlargeScreens="true"
/>

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name" 
    android:hardwareAccelerated="true">
    <activity  android:name="CordovaApp" android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

而cofig.xml是:

<?xml version='1.0' encoding='utf-8'?>
<widget id="XXXXXXX" version="0.0.1" xmlns="http://www.w3.org/ns/widgets"     
xmlns:cdv="http://cordova.apache.org/ns/1.0">

<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<access origin="*" subdomains="true" />

<log level="DEBUG"/>
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="true" />
<preference name="disallowOverscroll" value="true" />
<preference name="loadUrlTimeoutValue" value="60000" />

<feature name="Camera">
    <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
<feature name="File">
    <param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="Device">
    <param name="android-package" value="org.apache.cordova.device" />
</feature>
<feature name="NetworkStatus">
    <param name="android-package" value="org.apache.cordova.network-information" />
</feature>
<feature name="SplashScreen">
    <param name="android-package" value="org.apache.cordova.splashscreen" />
</feature>
<feature name="Globalization">
    <param name="android-package" value="org.apache.cordova.globalization" />
</feature>


经过一番搜索,我找到了答案

Android WebView默认情况下不允许自签名SSL证书。当应用程序进行调试签名时,SSL错误将被忽略,但如果应用程序进行释放签名,则连接到不受信任的服务时,SSL错误不会被忽略


如果您可以选择Intel XDK作为替代开发人员平台,则XMLHTTPRequest将起作用

请在此处查看我的代码: 将APK生成为混合遗留应用程序

我也有一个问题,但这是有关人行横道。但只有没有人行横道的Android APK运行良好。我担心您会卷入这一同源政策问题。也许你应该仔细检查一下

我的应用程序没有特定的清单。XDK正在管理和编译此文件。这部分对我来说仍然是一个黑匣子,因为我在这方面还很新

这段代码在我这边运行得很好

//***************************************************************************************************
// WS  THIS IS THE WS SECTION
//***************************************************************************************************

function XHRObject() {
    var xhr;

    xhr = new XMLHttpRequest();

    xhr.onerror = function () {};
    xhr.onstart = function () {};
    xhr.success = function () {};

    return xhr;
}

function getSphereParametersWSxhr() {
    var url = "http://192.168.2.171/transporter.asmx/getVideoCubeParameters";
    xhr = new XMLHttpRequest();
    var params = "";

    console.log(xhr);
    alert("before open POST : " + xhr);
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // forbidden xhr.setRequestHeader("Content-length", params.length);
    alert("after open POST : " + xhr);

    try {
        xhr.onreadystatechange = function () {

            alert ("xhr.readyState == " + xhr.readyState + " xhr.status == " + xhr.status + " xhr.statusText: " + xhr.statusText + " xhr.responseText" + xhr.responseText );

            if (xhr.readyState == 2 && xhr.status == 404) {
                console.log("404 page not found: " + xhr);
                alert("404 page not found: " + xhr);
            }
            if (xhr.readyState == 3) {
                console.log("ready state 3: " + xhr.statusText + " " + xhr.status);
                alert("ready state 3: " + xhr.statusText + " " + xhr.status);
            }
            if (xhr.readyState == 4 ) {                                                         //&& xhr.status == 200
                console.log("ready state 4: " + xhr.statusText + " " + xhr.responseText);
                alert("ready state 4: " + xhr.statusText + " " + xhr.responseText);

                var erg1 = xhr.responseXML.getElementsByTagName("spherePictures")[0].textContent;
                var stringList = erg1.split(";");
                console.log(erg1);
                alert("pictureList: " + erg1);
                alert(xhr.responseText);

            }

        }
        xhr.send(params);
    } catch (e) {
        console.log("XHR Post : " + e);
        alert("XHR Post : " + e);
    }
}
//***************************************************************************************************
// WS  THIS IS THE WS SECTION
//***************************************************************************************************

function XHRObject() {
    var xhr;

    xhr = new XMLHttpRequest();

    xhr.onerror = function () {};
    xhr.onstart = function () {};
    xhr.success = function () {};

    return xhr;
}

function getSphereParametersWSxhr() {
    var url = "http://192.168.2.171/transporter.asmx/getVideoCubeParameters";
    xhr = new XMLHttpRequest();
    var params = "";

    console.log(xhr);
    alert("before open POST : " + xhr);
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // forbidden xhr.setRequestHeader("Content-length", params.length);
    alert("after open POST : " + xhr);

    try {
        xhr.onreadystatechange = function () {

            alert ("xhr.readyState == " + xhr.readyState + " xhr.status == " + xhr.status + " xhr.statusText: " + xhr.statusText + " xhr.responseText" + xhr.responseText );

            if (xhr.readyState == 2 && xhr.status == 404) {
                console.log("404 page not found: " + xhr);
                alert("404 page not found: " + xhr);
            }
            if (xhr.readyState == 3) {
                console.log("ready state 3: " + xhr.statusText + " " + xhr.status);
                alert("ready state 3: " + xhr.statusText + " " + xhr.status);
            }
            if (xhr.readyState == 4 ) {                                                         //&& xhr.status == 200
                console.log("ready state 4: " + xhr.statusText + " " + xhr.responseText);
                alert("ready state 4: " + xhr.statusText + " " + xhr.responseText);

                var erg1 = xhr.responseXML.getElementsByTagName("spherePictures")[0].textContent;
                var stringList = erg1.split(";");
                console.log(erg1);
                alert("pictureList: " + erg1);
                alert(xhr.responseText);

            }

        }
        xhr.send(params);
    } catch (e) {
        console.log("XHR Post : " + e);
        alert("XHR Post : " + e);
    }
}