Search Unity

Access web service via HTTPS using proxy class

Discussion in 'Scripting' started by Coltess, Apr 6, 2010.

  1. Coltess

    Coltess

    Joined:
    Apr 2, 2010
    Posts:
    2
    Our game will be running behind a client's firewall and must access our server for various reasons. I am trying to create a connection between game and service using a proxy class. The connection works perfectly when I access the web service using HTTP, but when using HTTPS I get the following error message in Unity:
    and
    Anyone know if this is a Unity/Mono "feature" or do I need to "activate" HTTPS somehow?

    Thanks,
    Colt
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    I don't think mono 1.2.5 has HTTPS (fully) implemented.
    Especially in case of the Webplayer it wouldn't work anymore anyway (if you are using that) cause System.Environment is blocked in webplayers (as is System.IO and other local access paths)
     
  3. Coltess

    Coltess

    Joined:
    Apr 2, 2010
    Posts:
    2
    Thanks dreamora, that's what I was afraid of.
    And just for clarification, we are developing the game as a standalone application, not a web app.

    Colt
     
  4. Keld Oelykke

    Keld Oelykke

    Joined:
    Sep 12, 2009
    Posts:
    10
    I experience the same on Vista w. Unity 2.6.1f.
     
  5. Keld Oelykke

    Keld Oelykke

    Joined:
    Sep 12, 2009
    Posts:
    10
    If you just want to get access working (Note! Without any security checks!), here is a way around it:

    Code (csharp):
    1. ----
    2.         // KRO: Currently .net deprecated approach to have https support in unity w. old mono version
    3.         private class DummyCertificatePolicy : ICertificatePolicy
    4.         {
    5.             public DummyCertificatePolicy()
    6.             {
    7.                 ServicePointManager.CertificatePolicy = this;
    8.             }
    9.  
    10.             #region ICertificatePolicy Members
    11.  
    12.             public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
    13.             {
    14.                 return true;
    15.             }
    16.  
    17.             #endregion
    18.         }
    19.  
    20. ----
    Just make an instance of above dummy class before you call WebRequest.Create.

    Also note that above is a deprecated approach in newer .net platforms.

    Read more here: http://mono-project.com/FAQ:_Security