locked
Https Ajax call is not working

    Question

  • Hi ,

    I am trying to build an application where i can interact with server using https request.

    I am using follow

     $.ajax({
            url: url_server, //url_server is https://192.168.1.124:8443/my-rest-services
            type: "POST",
            cache: false,
            data: pjsonstring,
            dataType: 'json',
            timeout: 1000000,
            success: function (json) {
                fnAlert("success");
            },
            error: function (error) {
                fnAlert("fail");
                return "error";
            },
            async: false
        });

    But this code is failing showing "NETWORK ERROR".

    When i am trying to hit server using 

    http://192.168.1.124:8181/my-rest-services

    then its working fine.

    i have server where on port 8181 there is http service enable and on 8443 https service is enable..

    both services are working fine when i try to hit with browser...

    Please help me out to solve this problem ..

    Thanks in advance!!


    Thursday, March 14, 2013 6:11 AM

Answers

  • Hi Amit,

    You can install a certificate on a machine running a Windows Store app exactly the same way as the article explains.
    You can install a certificate on a Windows Phone by putting the .cer file on your server and navigating to it with the phone.  It will prompt you to install it and you can install it in the Root CA.  For example, put your cert here: https://192.168.1.124/root.cer, then point your phone browser there.  You can also 'Bing' How to install root server certificate on Windows Phone.  Again, first ensure you can hit the certificate with no errors in the browser before you try a Windows Store app and resolve any errors.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 14, 2013 12:27 PM
    Moderator

All replies

  • Hi Amit,

    You can start troubleshooting this by using WinJS.xhr.  This will help narrow down the problem.  My guess is that the server name does not match the certificate.  You can check for certificate problems by browsing to https://192.168.1.124:8443/appzillon-rest-services using Internet Explorer and see if you have any certificate errors or warnings.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 14, 2013 10:58 AM
    Moderator
  • HI Jeff,

    Thank for your reply...

    when i am browsing link with IE .. Its showing that 

    There is a problem with this website's security certificate.

    there are two option close this page and Continue with this web page..

    This is my local server where i have rest based services... which will serve me json string on hitting server..

    when i m trying to connect with "http" its working fine .. its creating problem with "https"


    Please help me to solve this issue in windows metro app

    Thank in advance


    Thursday, March 14, 2013 11:09 AM
  • Hi Amit,

    You cannot solve this issue in a Windows Store app (don't use the m* word :-) )because this is a problem with the server.  Your problem is that the server certificate must match the server name.  After you resolve all of the issues with the server certificate, then you will be able to use this service in your app.

    There is no workaround.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 14, 2013 11:13 AM
    Moderator
  • Hi Jeff,

    How that server certificate can be solved?

    Can you please help with the steps how to resolve that certificate issue with server..

    That server is created by myself .. I am using Apache server...

    Same app is also developing in IOS and its working fine in IOS .. They added some code in setting file and its working fine..

    Please help to solve this problem ...

    And very thankful to your assistance

    Thanking You, 

    Thursday, March 14, 2013 11:36 AM
  • Hi Amit,

    IOS probably lets you use an invalid Server Certificate.

    The URI you posted is not available from the Internet because it is an internal network address.  How does your production application hit this URI?

    This blog will help understand how to resolve some certificate errors:

    http://blogs.msdn.com/b/jpsanders/archive/2009/09/16/troubleshooting-asp-net-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 14, 2013 11:50 AM
    Moderator
  • Hi Jeff,

    For testing purpose we have created our own server on LAN and our apps are hitting server using AJAX call in following ways 

    $.ajax({ url: url_server, //url_server is https://192.168.1.124:8443/my-rest-services type: "POST", cache: false, data: pjsonstring, dataType: 'json', timeout: 1000000, success: function (json) { fnAlert("success"); }, error: function (error) { fnAlert("fail"); return "error"; }, async: false });

    In case of http its woking fine but In case of https request its going in error "NETWORK ERROR".

    please try to help us..

    Thanking You,



    Thursday, March 14, 2013 12:00 PM
  • Hi jeff,

    In your article you demonstrate that installing the certificate might help.

    but in the case of windows phone or windows Store App( :) )  How we can install Certificate on device..

    I think in that case it might not help.

    Any suggestion?

    Thursday, March 14, 2013 12:15 PM
  • See this post:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/4a776e8c-0e10-4f03-908f-7f765d914080

    Those are your only options.  For testing you can install the certificate in the Machine Trusted root store however Note that the certificate name must match the name of the host.  If you can generate a certificate with a the same name as your host (in your case an ip Address) then you will be successful.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 14, 2013 12:18 PM
    Moderator
  • Hi Amit,

    You can install a certificate on a machine running a Windows Store app exactly the same way as the article explains.
    You can install a certificate on a Windows Phone by putting the .cer file on your server and navigating to it with the phone.  It will prompt you to install it and you can install it in the Root CA.  For example, put your cert here: https://192.168.1.124/root.cer, then point your phone browser there.  You can also 'Bing' How to install root server certificate on Windows Phone.  Again, first ensure you can hit the certificate with no errors in the browser before you try a Windows Store app and resolve any errors.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 14, 2013 12:27 PM
    Moderator