Unable to send HTTPRequest using Photon Plugins

para_nautilus
edited March 2019 in Photon Server
I'm trying to make a HttpRequest to my azure server but it is throwing following error:



The underlying connection was closed: An unexpected error occurred on a send.

I would also like to know what all these code mean.
I tried same thing using Rest Sharp library , and it is throwing above error only in Load balancing solution.
There request works just fine on Postman and Windows console application.

Please help ASAP. :smile: Thank you :wink:

Update: Works with http:// could you help to get it working with https://?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @para_nautilus,

    I think you need to add support for TLS1.2 and SSL3 from the server.
    Try adding this in your server's code:
    System.Net.ServicePointManager.SecurityProtocol = 
                    SecurityProtocolType.Ssl3
                    | SecurityProtocolType.Tls
                    | (SecurityProtocolType)768 
                    | (SecurityProtocolType)3072;
  • para_nautilus
    edited March 2019
    For my .net version only TLS and SSL two types are supported. :# not the Ssl3 is not there only Ssl is there. and Tls is there
    I tried adding thoes two as it is mentioned here . it does not work. still throws same error.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Where did you apply the code?
    I think it needs to be applied from the server code and not from the plugin code.

    I think there is no need to update the .Net version but as you can see in the snippet above, we use hardcoded versions. You can always update the .Net framework version since you have the source code and the VS solution.
  • para_nautilus
    edited March 2019
    Oh server is working just fine, since postman/ can querry with https successfully, even a empty Visual Studio Windows Console Application can query this successfully, only problem is when this code runs on photon plugin.

    Anyway , i think have to install some kind of certificates i don't know how. I would be great full if you could point me to a source.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @para_nautilus,

    Did you solve this or not yet?
  • @JohnTube @para_nautilus
    I have the same issue. Web server is accessible publicly (tested with postman, too), but when the prefix is http, I get the error:
    The underlying connection was closed: An unexpected error occurred on a send.
    
    .
    However, change the prefix to http and it works correctly. I believe this is an API issue or an OS issue? I am running Windows Server 2012.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited November 2020

    hi @JPGOrdon,

    what Photon Server SDK version do you use?
    v4 or v5?

    this is probably an issue with the TLS/SSL support in the Photon Server SDK version you use and the Windows Server version.
    here is what you can do (depending on the .NET version and the level of security you want), from your server code, I think you can do it from the plugin itself (my colleague @chvetsov can confirm)

    System.Net.ServicePointManager.SecurityProtocol = 
                    // SecurityProtocolType.Ssl3 |
                    //SecurityProtocolType.Tls |
                    //(SecurityProtocolType)768 | // SecurityProtocolType.Tls11
                    (SecurityProtocolType)3072 | // SecurityProtocolType.Tls12
                    (SecurityProtocolType)12288; // SecurityProtocolType.Tls13
    

    but you may also want to modify a couple of registry values (@markus may know more about this):

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto = 00000001
    
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto = 00000001
    

    further readings:
    https://www.hass.de/content/setup-microsoft-windows-or-iis-ssl-perfect-forward-secrecy-and-tls-12
    https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

    we will probably add this information to our documentation in the future.

  • The easiest fix would be to use Photon Server v5 - it should just work (as it targets a newer .NET version).

    If using v4
    - do not use any version of SSL (treated as unsecure/broken) as SecurityProtocol
    - do not use TLS 1.0 (treated as unsecure/broken) as SecurityProtocol
    - apply the registry settings Hamza mentioned above (this makes .NET clients to use TLS)