Search Unity

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:
    2,013
    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:
    3,685
    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?