Search Unity

RestSharp in unity projects and iOS

Discussion in 'iOS and tvOS' started by cdiflora, Jan 31, 2013.

  1. cdiflora

    cdiflora

    Joined:
    Jan 31, 2013
    Posts:
    3
    Hi all,

    I was wondering if somebody succeeded in using RestSharp with unity3d.
    I managed to use it and let it work when running the game from the unity editor, but if I compile my project for iOS and try to run that on device, the Async calls (based on lambdas) do not seem to work properly.

    Code (csharp):
    1.         UnityEngine.Debug.Log ("[CDF] ***************************************");
    2.         UnityEngine.Debug.Log ("[CDF] Testing RESTSHARP calls)");
    3.         RestClient client = new RestClient();
    4.         client.BaseUrl = "https://myownserver.com";
    5.         RestRequest request = new RestRequest();
    6.         request.Resource = "myresourceURL";
    7.         client.ExecuteAsync(request, response =>
    8.         {
    9.             UnityEngine.Debug.Log("[CDF] RESPONSE CONTENT: " + response.Content);
    10.             UnityEngine.Debug.Log ("[CDF] RESPONSE STATUS CODE: " + response.StatusCode);
    11.             try
    12.             {
    13.             JsonObject jobj = (JsonObject)SimpleJson.DeserializeObject(response.Content);
    14.             object currentTime;
    15.             jobj.TryGetValue("time", out currentTime);
    16.             UnityEngine.Debug.Log ("[CDF] Deserialized value from json: " + currentTime);
    17.             } catch (System.Runtime.Serialization.SerializationException ex)
    18.             {
    19.                 UnityEngine.Debug.Log ("[CDF] Exception while Getting data via RestSharp: " + ex.Message);
    20.             }
    21.         });
    When run on iOS player, the response content is always empty and status code is 0, which suggests the request is not executed at all.
    When running such code in the unity editor, the code works as expected, and my lambda, where the response processing happens, is called properly.

    Any experience / comments on this topic would be very much appreciated.

    Br,
    -Cristiano
     
  2. cdiflora

    cdiflora

    Joined:
    Jan 31, 2013
    Posts:
    3
    It seems I am getting a NotSupportedException for System.Net.WebRequest.GetCreator, so the problem probably boils down to lack of support for Net.WebRequest in iOS.
    Am I right?