Home » Android » Soap query with jQuery / Phonegap always fail on Android

Soap query with jQuery / Phonegap always fail on Android

Posted by: admin May 14, 2020 Leave a comment

Questions:

I developed an iPhone/Android app with jQuery mobile & Phonegap (now Cordova). This app use different services with no problem. One of this services is a Soap one so i use the jsSOAPClient (jquery.jqSOAPClient.js) for jQuery in order to request the service. I have no problem at all from an iOS device but the query always fail on Android.

In jsSOAPClient the request looks like that :

        function getResponse(xData, status) {
            if(!!callback) {
                SOAPClient.Status = xData.status;
                SOAPClient.ResponseText = xData.responseText;
                SOAPClient.ResponseXML = xData.responseXML;
                callback(xData.responseXML);
            }
        }

        $.ajax({
             type: "POST",
             url: SOAPClient.Proxy,
             dataType: "xml",
             processData: false,
             data: content,
             complete: getResponse,
             beforeSend: function(req) {
                req.setRequestHeader("Method", "POST");
                req.setRequestHeader("Content-Length", SOAPClient.ContentLength);
                req.setRequestHeader("Content-Type", SOAPClient.ContentType + "; charset=\"" + SOAPClient.CharSet + "\"");
                req.setRequestHeader("SOAPServer", SOAPClient.SOAPServer);
                req.setRequestHeader("SOAPAction", soapReq.Action);
             }
        });

The “getResponse” “status” value is “error” and the “SOAPClient.Status” (equal to “xData.status”) value is “0”.

The server seems to not receive request at all…

I repeat that the same code with the same request datas have results on iOS.

Thanks for help.

/ EDIT */
I tried to comment the line :

//type: "POST",

it seems to work, i mean i have a 200 status code in this case even if i have a parse error due to the unexpected response format.

How to&Answers:

Apparently there is a bug in Android 2.x where setting the
“Content-length” header causes the problem you describe. It looks like
the bug has been fixed in Android 4.0.3. So try your code unmodified
in the 4.0.3 emulator and it should work then come back to 2.x and
remove the Content-length header to see if it works as well.