locked
WinJS.xhr Cross-Origin problem RRS feed

  • Question

  • Now I use WinJS.xhr function.

    It is very useful.

    But, I met with the status code 0.

    This problem seems to occur under cross origin situation.

    (execute from local file. request to the other domain. etc..)

    However, It does not seem to have any problem in such situation either.

    Which is the right?

    Sunday, November 6, 2011 2:58 PM

Answers

  • I meet similar issue. Finally I found it is caused by the manifest capabilities setting.

    you can check whether you have the following ones:

        <Capability Name="privateNetworkClientServer" />
        <Capability Name="internetClient" />

    Hope this can help.

    Wednesday, November 9, 2011 5:32 AM

All replies

  • Hello K,

    Can you provide a specific simple example of the problem you are having? 

    -Jeff


    Jeff Sanders (MSFT)
    Monday, November 7, 2011 12:45 PM
    Moderator
  • Hi.

    I implemented this authorization sequence.

    http://developer.mixi.co.jp/en/connect/mixi_graph_api/api_auth/

    I got Authorization code via Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync.

    Next, I have to POST request for to get access token.

    So I use xhr function but I got response status 0.

    This is my code.

     

    var clientID = "clientID";
    var clientSecret = "clientSecret";
    var callbackURL = "callBackURL";
    
    function launchMixiWebAuth() {
    
        var mixiURL = "https://mixi.jp/connect_authorize.pl?client_id=";
    
        if (clientID === null || clientID === "") {
            sdkSample.displayError("Enter a ClientID");
            return;
        }
    
        if (callbackURL === null || callbackURL === "") {
            sdkSample.displayError("Enter a Callback URL");
            return;
        }
    
        mixiURL += clientID + "&scope=r_profile%20r_voice&display=touch&response_type=code";
    
        try {
            var startURI = new Windows.Foundation.Uri(mixiURL);
            var endURI = new Windows.Foundation.Uri(callbackURL);
    
            Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync(
                    Windows.Security.Authentication.Web.WebAuthenticationOptions.default,
                    startURI,
                    endURI).then(callbackMixiWebAuth, callbackMixiWebAuthError);
    
    
        } catch (err) {
            return;
        }
    
    }
    
    function callbackMixiWebAuth(result) {
        window.console.log(result.responseData);
        window.console.log(result.responseStatus);
    
        if (status == 2) {
            window.console.log("Error returned: " + result.responseErrorDetail);
        }
    
        var resposeURI = new Windows.Foundation.Uri(result.responseData);
        var queryPair = resposeURI.query.split("=");
    
        if (queryPair[0] == "?code") {
            var code = queryPair[1];
            window.console.log("code:" + code);
            var requestData = "grant_type=authorization_code&client_id=" + clientID +
                "&client_secret=" + clientSecret +
                "&code=" + code +
                "&redirect_uri=" + encodeURIComponent(callbackURL);
            window.console.log("data:" + requestData);
    
            WinJS.xhr({
                type: "POST",
                url: "https://secure.mixi-platform.com/2/token",
                headers: { "Content-type": "application/x-www-form-urlencoded" },
                data: requestData
            }).then(function (result) {
                window.console.log(result);//I can't reach.
            }, function (result) {
                window.console.log(result);//I got status 0.
            });
    
        }
    }
    
    

     


    I don't know that Metro style can apps access cross origin data source or not.

    However, I could find status 0 only this URL.

    I'll check server side settings.


    • Edited by k_kinukawa Tuesday, November 8, 2011 1:34 AM
    Tuesday, November 8, 2011 1:33 AM
  • I meet similar issue. Finally I found it is caused by the manifest capabilities setting.

    you can check whether you have the following ones:

        <Capability Name="privateNetworkClientServer" />
        <Capability Name="internetClient" />

    Hope this can help.

    Wednesday, November 9, 2011 5:32 AM
  • Thank you for your information.

    I try to your suggestion.

    but status code didn't change.

    (All capability checked, but it also.)

     

    I think it is server side problem.

    Because, another domain reply normal status like 200, 40x.

    So , I ask customer support.

    Thursday, November 10, 2011 12:50 AM
  • Did you get your problem resolved? 
    Jeff Sanders (MSFT)
    Tuesday, November 22, 2011 9:06 PM
    Moderator
  • hi.

    I was under a different task.

    today, I try to this issue and I received status code 200!

    I don't know why did this problem clear.

    (code is not changed.)

    Thanks a lot.

    Tuesday, January 24, 2012 1:08 PM
  • Thanks fanybruce, that fixed my problem!

    Paul Lambadaris SingularLogic SA


    Tuesday, November 13, 2012 4:08 PM