locked
WinJS.xhr request works on dev machine but not production machine for https request

    Question

  • I use a WinJS.xhr request to get JSON from a server in order to populate a page in my app. The code works fine when I test it on the machine I am developing it on. When I deploy the app locally on another windows 8 machine the app fails to make the xhr request. the link I requesting content from is https link address. I believe this could be the reason why it does not work but I don’t get any messages from the error handler. Here is the code below.

    var theURL = "https://secureservercom/handler.php?anum=" + credentialPickerResults.credentialUserName + "&pin=" + credentialPickerResults.credentialPassword + "&kcode=ddd";
                            WinJS.xhr({ url: theURL }).done(
                                function oncomplete(request) {
                                    var tmpList = Array();
                                    tmpList = JSON.parse(request.responseText);
                                    if (tmpList.success == "1") {
                                        //Successfully retrieved the record
                                        document.getElementById("aNum").innerText = tmpList.aNum;
                                        document.getElementById("expDate").innerText = tmpList.expDate;
                                        document.getElementById("fullName").innerText = tmpList.fname + " " + tmpList.lname;
                                        document.getElementById("creditHrs").innerText = tmpList.creditHrs;
                                        document.getElementById("tAward").innerText = tmpList.tAward;
                                        document.getElementById("asOfDate").innerText = tmpList.asOfDate;
                                        document.getElementById("tNFees").innerText = tmpList.tNFees;
                                        document.getElementById("bvAmt").innerText = tmpList.bvAmt;
    
                                        WinJS.UI.Animation.fadeIn(document.querySelector("#content"));
                                        //document.getElementById("content").style.visibility = "visible";
                                    } else if (tmpList.success == "2") {
                                        //Incorrect format message
                                        displayDiag(incorrFormatMsg);
                                    }
                                },
                                function onerror(e) {
                                    //Connection error message
                                    //displayDiag(errorMsg);
                                    //console.log(e.detail.exception);
                                    if (e.message != undefined) {  // If the URL is really malformed or blank.
                                        document.getElementById("content").innerHTML = "Got message error: " + e.message;
                                    }
                                    else if (e.statusText != undefined) {
                                        document.getElementById("content").innerHTML = "Got estatus error: " + e.statusText;
                                    }
                                    else {
                                        document.getElementById("content").innerHTML = "Got wierd error: " + e.statusText;
                                    }
                                    WinJS.UI.Animation.fadeIn(document.querySelector("#content"));
                                });
                        }

    Friday, May 24, 2013 8:00 PM

All replies

  • Do you need a certificate that is used on the server to be installed on the machine where the client is .. That could be one of the reason..

    Can you get the JSON when you put the url in IE on the other machine ?

    - Girija

    Friday, May 24, 2013 8:51 PM
  • Yes, when I open IE from the start screen and enter the web address in the browser as just like xhr would do I get the JSON string as the response.
    Wednesday, May 29, 2013 3:02 PM
  • I also want to add that the e.statusText property is defined at the time of the error but all I get in the "content" ID html tag is "Got estatus error: ".
    Wednesday, May 29, 2013 5:30 PM
  • Do you have any authentication token/header to be passed.. Usually the https calls require a header (authentication header) to be passed.

    If you have that then you need to do this :

     WinJS.xhr({
                type: "GET", url: <<Full url>>
                headers: { "Authorization": << Authorization header / token >> }
            }).done( ....
    

    IE usually works by default if you have logged on a computer with the credentials that has access. IE will take that by default.

    To cross check if you need to pass authentication try on a machine that is logged on a local user and has access to the internet..

    - Girija

    Wednesday, May 29, 2013 6:39 PM
  • I don't believe I need to because it works on the development machine. The server that I am trying to get the information from has another program I wrote that looks at the "kcode=ddd" to validate that it is coming from a legitimate source (UNIX server). Later on in the development I am going to lock that down but for now it should be fine. The development machine is on a computer separate from the server. The development machine is a local machine and void of a domain affiliation. Now the other machine that the windows 8 app is being finally tested on is added to a domain but I don't think that should be an issue seeing that the server is not part of that domain and does not use the domain to authenticate anything.
    Thursday, May 30, 2013 3:43 PM
  • So I have another app that does a similar xhr request to a PHP script via GET/HTTP and not HTTPS and it works fine. My suspicion is that the https is the problem and is why I am not getting anything back with the above code.
    Tuesday, June 4, 2013 3:47 PM
  • Added progress function to xhr request and it gives ready state 2 and 3, and then loads the page in my development environment. When I deploy the app in the production machine it only shows that their was a statusText error. It is like the xhr is being blocked before it even makes the request. Here is the updated code below:

    credentialPickerResults = result;
                            var theURL = "https://secureservercom/handler.php?anum=" + credentialPickerResults.credentialUserName + "&pin=" + credentialPickerResults.credentialPassword + "&kcode=ddd";
                            WinJS.xhr({ url: theURL }).done(
                                function oncomplete(request) {
                                    var tmpList = Array();
                                    tmpList = JSON.parse(request.responseText);
                                    if (tmpList.success == "1") {
                                        //Successfully retrieved the record
                                        document.getElementById("aNum").innerText = tmpList.aNum;
                                        document.getElementById("expDate").innerText = tmpList.expDate;
                                        document.getElementById("fullName").innerText = tmpList.fname + " " + tmpList.lname;
                                        document.getElementById("creditHrs").innerText = tmpList.creditHrs;
                                        document.getElementById("tAward").innerText = tmpList.tAward;
                                        document.getElementById("asOfDate").innerText = tmpList.asOfDate;
                                        document.getElementById("tNFees").innerText = tmpList.tNFees;
                                        document.getElementById("bvAmt").innerText = tmpList.bvAmt;
    
                                        WinJS.UI.Animation.fadeIn(document.querySelector("#content"));
                                    } else if (tmpList.success == "2") {
                                        //Incorrect format message
                                        displayDiag(incorrFormatMsg);
                                    }
                                },
                                function onerror(e) {
                                    //Connection error message
                                    //displayDiag(errorMsg);
                                    //console.log(e.detail.exception);
                                    if (e.message != undefined) {  // If the URL is really malformed or blank.
                                        document.getElementById("content").innerHTML = "Got message error: " + e.message;
                                    }
                                    else if (e.statusText != undefined) {
                                        document.getElementById("content").innerHTML = "Got estatus error: " + e.statusText;
                                    }
                                    else {
                                        document.getElementById("content").innerHTML = "Got wierd error: " + e.statusText;
                                    }
                                    WinJS.UI.Animation.fadeIn(document.querySelector("#content"));
                                },
                                function progress(result) {
                                    var xhrDiv = document.getElementById("xhrdiv");
                                    var accumalated_state = xhrDiv.innerText + '\n';
                                    xhrDiv.innerText = accumalated_state + "Ready state is " + result.readyState;
                                    //xhrDiv.style.backgroundColor = "#0000FF";
                                });

    Tuesday, June 4, 2013 4:56 PM
  • I almost figured it out. The issue seems to lie in the communication between the computer and the server. I was able to get the app to connect to the server when I used "Fiddler2" with "Windows 8 Lookback Exceptions". Unfortunately "fiddler 2" didn't give much information as to why the app worked because all it captured was the successful connection. This made me think that maybe this had something to do with IE's security. Seeing that WWAHOST is like a IE web browser minus the chrome, I suspected WWAHOST was rejecting sending HTTPS request. Then I noticed that my development machine was not on the network's domain and the TEST machine for production was. This means that the firewall profile is different at the O.S. level. So I dropped the TEST computer off of the domain and now it works. This begs the question as to why would the computer's not be able to make WinJS.xhr HTTPS request while the TEST computer was on he domain and successfully connected when not on the domain?
    Wednesday, June 5, 2013 7:36 PM
  • bump
    Friday, June 21, 2013 7:21 PM
  • Bump?
    Thursday, June 27, 2013 3:21 PM
  • Bump......
    Thursday, July 11, 2013 12:49 AM