Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

UnityWebRequest GET problem

Discussion in 'Android' started by primebit, Oct 11, 2018.

  1. primebit

    primebit

    Joined:
    Jun 24, 2015
    Posts:
    2
    Hello,
    we have problem with using UnityWebRequest to get some data from our API. On other platform's like PC it's working fine. On Android instead of sending GET request it send's always POST (checked in Fiddler). It's really weird.
    Below the code snippets.

    Class:
    Code (CSharp):
    1. public class BaseRequest
    2. {
    3.     protected UnityWebRequest webRequest;
    4.  
    5.     public BaseRequest(string serviceUrl, string endpoint, string method)
    6.     {
    7.         webRequest = new UnityWebRequest();
    8.         webRequest.downloadHandler = new DownloadHandlerBuffer();
    9.  
    10.         webRequest.url = serviceUrl + endpoint;
    11.  
    12.         webRequest.method = method;
    13.  
    14.         webRequest.SetRequestHeader("X-Requested-With", "XMLHttpRequest");
    15.  
    16. //...
    17.  
    18.     }
    19.  
    20. public IEnumerator Send()
    21.     {
    22.        /...
    23.         yield return webRequest.SendWebRequest();
    24.     }
    25. }
    Coroutine for sending:
    Code (CSharp):
    1.   private IEnumerator SendSomething()
    2.     {
    3.         var request = new BaseRequest(ServiceURL, "", "GET");
    4.  
    5.         yield return request.Send();
    6.  
    7.         //...
    8.     }
    Anyone had problem like that?
     
    Last edited: Oct 11, 2018
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    1,841
    Check you code more thoroughly. UnityWebRequest definitely can send GET request and does so when method is set to GET.
    Try to reduce your code to the simple piece that only does the request.
     
  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    2,410
    What is the value of the variable "method" in the first routine? You can use Debug.Log at runtime to determine. And where are you calling SendSomething?