0

I have a Unity project where I'm trying to scrape images from websites but some of the URL's that I try to download images from don't work. So for example, if I try to use UnityWebRequestTexture.GetTexture() with this URL (https://cdn.shopify.com/s/files/1/1963/1339/files/G20-full-right-front.jpg) I'm able to download the image but if I use this URL (https://pisces.bbystatic.com/image2/BestBuy_US/images/products/6427/6427116_sd.jpg) I get nothing

I've stepped through the code in a debugger and when I call www.SendWebRequest(); it never returns so I never get a HTTP error or a response.

Here is my code:

private IEnumerator LoadImage(string url)
   {
      using (var www = UnityWebRequestTexture.GetTexture(url))
      {
         yield return www.SendWebRequest();
         if (www.isNetworkError)
         {
            Debug.Log(www.error);
         }
         else
         {
         
            Texture2D texture = null;
            try
            {
               texture = DownloadHandlerTexture.GetContent(www);
 
            }
            catch (Exception)
            {
               Destroy(gameObject);
               yield break;
            }
 
            // do something with the texture
            ...
         }
      }
   }

I'm guessing there is some kind of CORS issue or else some kind of SSL cert issue. But I don't know what I could do to solve these issues.

Ace
  • 11
  • 3
  • 1
    I don't think it is failing silently .. only your implementation is. Which Unity version are you using? You should not only check `isNetworkError` but also [`isHttpError`](https://docs.unity3d.com/2019.4/Documentation/ScriptReference/Networking.UnityWebRequest-isHttpError.html) .. you can also simply check `if(!string.IsNullOrWhiteSpace(www.error))` then whatever error is there it will be printed – derHugo Jan 24 '22 at 04:00
  • When I send a request there is never a response from the server. When I call www.SendWebRequest(); it never returns so I never get a HTTP error. I've added more network checks but these checks never get called. – Ace Jan 29 '22 at 03:45

0 Answers0