UnityWebRequest to Local Network Shared Folder

Im trying to download a picture from Windows Shared folder.
Here’s my code:

   public async Task<Texture2D> ReadTexture(string path)
   {
       if (path.StartsWith(@"\\"))
           path = @"file:\\" + path;

       print(path); //output: file:\\\\DESKTOP-89HPKIQ\shared\cute.jpg

       using (var request = UnityWebRequestTexture.GetTexture(path))
       {
           request.SendWebRequest();
 
           while (!request.isDone)
           {
               await Task.Yield();
           }

           if (request.result == UnityWebRequest.Result.Success)
           {
               var texture = DownloadHandlerTexture.GetContent(request);
;
               texture.name = Path.GetFileName(path);
               ConsoleWindow.Instance.Print($"Image loaded: {texture.name}");
               return texture;
           }
           else
           {
               ConsoleWindow.Instance.Print(request.error);
               print(request.error);
               print(request.url);
               print(request.uri);
               return null;
           }
       }
   }

The folder (\DESKTOP-89HPKIQ\shared):

The output:

I tried 3 slashes. It gives me HTTP/1.1 404 Not Found
I tried 2: Curl error 3: URL rejected: Port number was not a decimal number between 0 and 65535

Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:

And setting up a proxy can be very helpful too, in order to compare traffic:

Checked outside unity.
windows forms:

 private void Form1_Load(object sender, EventArgs e)
{
     string path = @"\\DESKTOP-89HPKIQ\shared";

     var files = Directory.GetFiles(path);

     pictureBox1.Image = Image.FromFile(files[0]);
     pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}

Works perfectly.
I use the same path in unity.

You most likely have the wrong number of slashes behind the file protocol. You usually have an additional slash when you’re on localhost. However you specify a different host, so you most likely need “less” slashes. Try with 3 or 2. There are many variants and Unity may not necessarily support network paths. Though those are the first things I would try.

ps: URLs use forward slashes / not backslashes \.

FIXED!
You need to inverse slashes:

 if (path.StartsWith(@"\\"))
{
     path = path.Replace(@"\", @"/");
     path = @"file://" + path;
}

Full code:

   public async Task<Texture2D> ReadTexture(string path)
   {
       if (path.StartsWith(@"\\"))
       {
           path = path.Replace(@"\", @"/");
           path = @"file://" + path;
       }

       print(path); //output: file:////DESKTOP-89HPKIQ/shared/cute.jpg

       using (var request = UnityWebRequestTexture.GetTexture(path))
       {
           request.SendWebRequest();
    
           while (!request.isDone)
           {
               await Task.Delay(3000);
           }

           if (request.result == UnityWebRequest.Result.Success)
           {
               var texture = DownloadHandlerTexture.GetContent(request);
;
               texture.name = Path.GetFileName(path);
               ConsoleWindow.Instance.Print($"Image loaded: {texture.name}");
               return texture;
           }
           else
           {
               ConsoleWindow.Instance.Print(request.error);
               print(request.error);
               print(request.url);
               print(request.uri);
               return null;
           }
       }
   }

Yeah, just fixed it! Thank you!

We need 2 slashes for file:// and +2 from local network path.
Correct me if im wrong

When accessing Windows shares, the correct number of slashes 5. Unity does work with 4 too as a side effect of supporting file://c/folder/… (which itself isn’t actually correct according spec).
The file:// is a protocol prefix (with two slashes), which is supposed to start with Unix style path, which, when absolute, starts with a slash. The network share prefix of \ has to be changed to forward slashes and appended to the slash indicating a root, so “file://” + “/” + “//shared_name”.

BTW, I think “smb://share_name” should work too (and not only on Windows).