Search Unity

UnityWebRequest does not work on Linux dedicated server

Discussion in 'Multiplayer' started by TheLastVertex, Feb 17, 2019.

  1. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    I'm posting this here in the hopes of getting more visibility compared to the Linux forum since I'm assuming this could affect anyone running dedicated servers.

    Calling UnityWebRequest on Linux results in "Network Error: Unknown Error" and Status Code "0". Making this same call on windows works fine and returns Status Code "200".

    I've attempted to use System.Net.WebClient instead but that results in a certificate error, even on windows. Overriding ServerCertificateValidationCallback to always return true does allow me to send the request on both Windows and Linux, but I assume that is not a valid or safe solution.

    After some googling it appears UnityWebRequest does not work on all Linux platforms due to potential issues with locating certificates. I can only confirm this does not work on Amazon Linux but it could potentially affect all non Ubuntu versions.

    Is there a solution for sending Http requests from a Linux dedicated server?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Certificate issues should manifest in error message from UWR. Can you try doing HTTP instead of HTTPS on the same server?
    A totally blind guess: check the environment variables for proxy settings. Unity picks those when they are present.
     
  3. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    Sorry for delay getting back on this. Also please correct me if I say something wrong, the only bits I know about Http requests is what I've scraped together trying to debug this over the last couple days.

    As for http vs https test results:

    Amazon Linux (GameLift) - UnityWebRequest.Get("http://www.google.com") returns Status Code "200". So all good there.
    Amazon Linux (GameLift) - UnityWebRequest.Get("https://www.google.com") returns Status Code "0" and "Network Error: Unknown Error".

    Now I was originally using UnityWebRequest.Post() but I'm assuming if Get fails Post will as well. I just wanted to eliminate my specific URL from the potential variables.

    Unfortunately I don't think using Http is an option. Its a 3rd party server I have to send the post request to and they require Https as far as I can tell. I did attempt to use http but it was blocked. I'm assuming overriding the cert validation callback as I did before is probably the same as sending plain http, even though it's fooling into thinking it's https? It's a work around at least.

    I'm still looking into the environment variables and proxy settings. I'm not sure if I have access to those with GameLift so I'm waiting to hear back. I'll let you know as soon as I hear anything.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    That makes a difference. If HTTP works and HTTPS doesn't, it an indication of bug.
    Actually I've remembered one issue about this. The CA certificate location differs on Debian-based and Red Hat-based distros, Unity used to look for Debian location only. I think this has been fixed, but you can try symlinking certificate file so it's found in a Debian location, maybe that will help.
     
  5. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    Do you have any suggestions on how to go about symLinking? I'd prefer if there is something I could include in the Unity project itself, but most solutions I find seem to be executed through Linux command line.
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    I don't think you'll be able to do this with Unity project, symlinking should require root privileges.
    Which Unity version are you using?
     
  7. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    Unity v2018.2.11f1
     
  8. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    Success! I was able to create the symLink through an install.sh shell script. I can now send Https requests using UnityWebRequest().

    For anyone that is interested here is the shell script "install.sh" I ended up with:
    Code (CSharp):
    1. #!/bin/bash
    2. sudo chmod 755 install.sh
    3. sudo mkdir -p /etc/ssl/certs
    4. cd /etc/ssl/certs
    5. sudo ln -s /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
    6.  
    Also Notepad++ has a handy option to make the text file compatible by cleaning up some of the white space. Under the Edit Menu -> EOL Conversion -> UNIX /OSX Format

    Thanks for the help!
     
  9. pixel_maniacs

    pixel_maniacs

    Joined:
    Jun 25, 2015
    Posts:
    71
    Thank you so much!
     
  10. AAAAAAAAAE

    AAAAAAAAAE

    Joined:
    Jun 8, 2013
    Posts:
    100
    Localhost request:

    For Ubuntu 20.04.5 LTS
    $ sudo ln -s /etc/ssl/certs/ca-certificates.crt /usr/local/share/ca-certificates/ca-bundle.crt
    sudo update-ca-certificates
     
    Last edited: Jan 9, 2023