Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

UnityWebRequest.Get error

Discussion in 'Scripting' started by paweleck, Oct 10, 2019.

  1. paweleck

    paweleck

    Joined:
    Jul 24, 2017
    Posts:
    7
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Could you paste the actual code that you use?
     
  3. paweleck

    paweleck

    Joined:
    Jul 24, 2017
    Posts:
    7
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4.  
    5. public class ButtonsHandler : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.         StartCoroutine(GetRequest("https://www.kinówki.pl"));
    11.         StartCoroutine(GetRequest("https://www.xn--kinwki-dxa.pl"));
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.      
    18.     }
    19.  
    20.     IEnumerator GetRequest(string uri)
    21.     {
    22.         using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
    23.         {
    24.             // Request and wait for the desired page.
    25.             yield return webRequest.SendWebRequest();
    26.  
    27.             string[] pages = uri.Split('/');
    28.             int page = pages.Length - 1;
    29.  
    30.             if (webRequest.isNetworkError)
    31.             {
    32.                 Debug.Log(pages[page] + ": Error: " + webRequest.error);
    33.             }
    34.             else
    35.             {
    36.                 Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
    37.             }
    38.         }
    39.     }
    40. }
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    The code looks good. It seems the second URI redirects to first, try debugging the request using tools like Fiddler or Charles.
    I can only guess that the special character causes the problem due to encoding or something like that.
     
  5. paweleck

    paweleck

    Joined:
    Jul 24, 2017
    Posts:
    7
    When I add code like this:
    Code (CSharp):
    1.             var request = (HttpWebRequest)WebRequest.Create("https://www.xn--kinwki-dxa.pl");
    2.             var response = (HttpWebResponse)request.GetResponse();
    3.             string responseString;
    4.             using (var stream = response.GetResponseStream())
    5.             {
    6.                 using (var reader = new StreamReader(stream))
    7.                 {
    8.                     responseString = reader.ReadToEnd();
    9.                 }
    10.             }
    I get more specific error:
    TlsException: Handshake failed - error code: UNITYTLS_INTERNAL_ERROR, verify result: UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED

    Is there any way to get around it (Im not owner of the domain)?
     
  6. paweleck

    paweleck

    Joined:
    Jul 24, 2017
    Posts:
    7
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    UnityWebRequest has ability to attach SertificateHandler that would trust any website. Such alternative also exists in .NET APIs.
    However I'm not sure this will help you. This has to be certificate issue in the first place. Have you tried Fiddler?
     
  8. charmcrescini

    charmcrescini

    Joined:
    Sep 9, 2019
    Posts:
    18
    Is UnityWebRequest be deprecated? Do you have suggestions for alternatives? Or is there a thread of community about alternatives to UnityWebRequest?
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    No, UnityWebRequest is not deprecated. Where did you get an idea about it?
     
  10. charmcrescini

    charmcrescini

    Joined:
    Sep 9, 2019
    Posts:
    18
    Oh okay. I saw that UNet will be deprecated. Will it not affect the UnityWebRequest class?
     
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    No, UnityWebRequest and UNet are separate things.
     
  12. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,132
    I have the same issue with error log UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED
    - Charles does not easily want to track SSL website calls from Unity applications due to a certificate error. This is a very common tool to track server calls (though not sure on SSL sites) so unfortunate, but maybe someone has the solution

    Edit, found a helpful Unity article to fix: https://support.unity3d.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity
     
    Last edited: Jul 24, 2020