Search Unity

No Post Method For Unitywebrequesttexture

Discussion in 'Scripting' started by GeoCats, Apr 10, 2019.

  1. GeoCats

    GeoCats

    Joined:
    Oct 4, 2018
    Posts:
    7
    Hello, in our mobile game, we have some images to download, and all of them need to be downloaded from the server using POST method.
    The UnityWebRequest class has the option to use it, but UnityWebRequestTexture only has GET option.
    So we are forced to use legacy WWW class for this...
    Is there ever going to be a way to use POST with UnityWebRequestTexture?
    Thank you!
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    You are not forced to anything. UnityWebRequestTexture only has common convenient methods. All they do is configure UnityWebRequest.
    A simplest way to achieve what you want is to do UnityWebRequest.Post and then assign DownloadHandlerTexture to downloadHandler property. It has a small cost of creating and discarding DownloadHandlerBuffer. It you want to avoid that, configure everything yourself.
     
  3. GeoCats

    GeoCats

    Joined:
    Oct 4, 2018
    Posts:
    7
    Thanks for the answer, but what does exactly mean "configure everything yourself"? You mean an alternative approach still using UnityWebRequestTexture? Or you mean developing from scratch a way to download images?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    In means creating UnityWebRequest with new operator and either using the correct constructor with desired values or setting relevant properties after creation. All these UnityWebRequest.Get and similar are just convenience methods on top of that, they create new UWR and set the url, method, download and upload handlers to certain values.

    See:
    https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-ctor.html
     
  5. GeoCats

    GeoCats

    Joined:
    Oct 4, 2018
    Posts:
    7
    Got it, I understand how it works now, thank you!