Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

This must be simple, how to do UnityWebRequest.Get from dynamic in game link?

Discussion in 'Scripting' started by FranFndz, Mar 12, 2021.

  1. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Well.. that's it.

    If I have
    string call = "me";
    UnityWebRequest.Get("www.domain.com/call?=" + call)

    works with no problem.
    but if I do:
    string domain = "domain";
    UnityWebRequest.Get("www." + domain + ".com/call?=" + call)

    It just start throwing certificate error issues.
    Any way to do those
    www.certificateHandler = new WebRequestCert();

    in game?
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Post the exact code you tested (with code tags) and the exact error message you're getting.

    Get() only sees the final string that you actually pass to it, not the steps that you used to create that string, so it can't possibly be behaving differently based on how you created the string. There has to be some difference other than that.

    Certificate errors suggest to me that you're accessing a different web site between the two test cases. Spelling error in the URL, maybe?

    If you're really convinced you're using identical strings, then try comparing the two strings in code.
     
  3. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    Are you also missing https:// from your examples?
     
  4. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Nop. Will post code later.

    I even debug the URI, copy the console link.ñ, Paste in browser and no problem.

    I also thought about misspelling so I did super simple test like:
    https://www.” + domain + “.com/call”...

    by the way; the domain string is set using a stringbox in canvas (dynamic, user input )

    May be some very simple human error.

    Will copy the code ASAP!
     
  5. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    ok, this is simple Github using my server for test

    https://github.com/resetme/Unity_WebRequestError

    I also have tried making the certificate return alway True, but it still give me error (server error)

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using TMPro;
    5. using UnityEngine;
    6. using UnityEngine.Networking;
    7.  
    8. public class WebRequestTest : MonoBehaviour
    9. {
    10.     public TextMeshProUGUI keyLabel;
    11.     public TextMeshProUGUI domainLabel;
    12.  
    13.     public TextMeshProUGUI consoleKey;
    14.     public TextMeshProUGUI consoleDomain;
    15.  
    16.     public void TestKeyCall()
    17.     {
    18.         StartCoroutine(PingServer(0));
    19.     }
    20.  
    21.     public void TestDomainCall()
    22.     {
    23.         StartCoroutine(PingServer(1));
    24.     }
    25.  
    26.     private IEnumerator PingServer(int value)
    27.     {
    28.         string createUrl = string.Empty;
    29.      
    30.         switch (value)
    31.         {
    32.             case 0: // Test Key
    33.                 createUrl = "https://franfndz.com/Unity/pingResponse.php?appView=" + keyLabel.text;
    34.                 break;
    35.             case 1: // Test Domain // Will give Error
    36.                 createUrl = UnityWebRequest.UnEscapeURL("https://" + domainLabel.text + ".com/Unity/pingResponse.php?appView=domainTest");
    37.                 break;
    38.              
    39.         }
    40.  
    41.         Debug.Log(createUrl);
    42.      
    43.         if (string.IsNullOrEmpty(createUrl))
    44.             yield break;
    45.  
    46.      
    47.         string answer = string.Empty;
    48.      
    49.         using (UnityWebRequest www = UnityWebRequest.Get(createUrl))
    50.         {
    51.             www.SendWebRequest();
    52.  
    53.             while (!www.isDone)
    54.             {
    55.                 yield return new WaitForEndOfFrame();
    56.             }
    57.  
    58.             answer = createUrl;
    59.             answer += "\n";
    60.          
    61.             if (www.isNetworkError)
    62.             {
    63.                 answer += www.error;
    64.             }
    65.             else
    66.             {
    67.                 answer += www.downloadHandler.text;
    68.                  
    69.             }
    70.         }
    71.  
    72.         switch (value)
    73.         {
    74.             case 0: // Test Key
    75.                 consoleKey.text  = answer;
    76.                 break;
    77.             case 1: // Test Domain
    78.                 consoleDomain.text = answer;
    79.                 break;
    80.         }
    81.     }
    82. }
    83.  
     
  6. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    google a little more I found this;

    Regex.Replace(createUrl, @"[^\u0000-\u007F]+", string.Empty);

    Now is working from dynamic text input. :D