Search Unity

UnityWebRequest returns 404 if URI contains 'plus' and 'space' characters

Discussion in 'Editor & General Support' started by dotsquid, Oct 8, 2021.

  1. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    When the URI contains 'plus' and 'space' characters, UnityWebRequest will fail with a 404 error, despite the target resource (file) does exist.
    This was noticed on PC (not sure about other platforms). The bug was reported yet on Sept. 22 and still no reply about it. https://fogbugz.unity3d.com/default.asp?1367599_7lnu7f617fm07sdd
    Can anyone from Unity comment on it? It's kinda critical.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    You have to escape your URI.
    In URI spece characters are not allow and plus character can be used as an excape for space, elternatively %20 can be used as escape sequence. We try to detect if provided URI is escaped or not, but having both pluses and spaces confuses things. Recommendation is to always use properly escaped URIs.
     
  3. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Did you check the code I used to reproduce this issue? It's attached to the bug report I mentioned above.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Unity does support passing Uri class directly to UnityWebRequest. If your original path is correct (Fix.Exists return true), the passing Uri should work.
    Have you checked the value AbsoluteUri that you eventually pass in? How it's escaped?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please share the runtime output of Debug.Log("URI = " + absoluteURI.ToString()); when you see this issue.
     
  6. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    For the path "E:/Projects/Unity3d/BugReports/UnityWebRequest_LocalFile/Assets/StreamingAssets\\+ Plus with space/Image.png" absoluteURI returns "file:///E:/Projects/Unity3d/BugReports/UnityWebRequest_LocalFile/Assets/StreamingAssets/+%20Plus%20with%20space/Image.png"
    Full path is constructed this way
    Path.Combine(Application.streamingAssetsPath, localPath)
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it! And it works as expected without the spaces?
     
  8. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Exactly. If the path contains either "space" character or "plus" character, it works fine. But not when the path contains them both.

    PS. Actually, I've prepared a pretty illustrative minimal reproducible example and we could save this time if you just launched it. But anyway, thanks for showing the interest, I hope this conversation will help fix this issue.
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Have you tried passing Uri object directly into UnityWebRequest?
     
  10. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Hi, sorry I somehow missed your message.
    Yes, I did. It was the first way I tried. The same issue.