proyecto26 / RestClient

🦄 A Promise based REST and HTTP client for Unity 🎮
https://assetstore.unity.com/packages/slug/102501
MIT License
1.24k stars 173 forks source link

Getting information out of RestClient Request #212

Closed Greyfox2k18 closed 2 years ago

Greyfox2k18 commented 2 years ago

I'm trying to get the information of the JSON request I'm making. In the examples it says that you can serialize the returned JSON to the class(TestDeck) but its not referencing an instance of the class. So how do I reference the created instance later on? With the debug on I can see I'm getting the requested JSON I want, and it's not flagging any errors.

I've tried passing the

response.Text.ToString()

to a function while just making RestClient.Request and process the JSON my self but it seems to call the function before the response is completed.

All I really need to do is get the text out of the response after the request is done. Nothing I've done has worked :(

I really appreciate any help in advance.

`public void getCard(int number) {

    string basicAPI_Key = "OELZN-4DCXM-5L611-86F16-E2811";
    auth test = new auth();
    test.key = basicAPI_Key;
    test.request = "deckList";
    string ou;

    string output = JsonConvert.SerializeObject(test);
    Debug.Log(output);

    byte[] outputToServer = Encoding.ASCII.GetBytes(output);

    RestClient.GetArray<TestDeck>(new RequestHelper
    {
        Uri = "http://localhost/cardgame/usersc/plugins/apibuilder/examples/getCardList.php",
        ProgressCallback = percent => Debug.Log(percent),
        EnableDebug = true,
        //ParseResponseBody = true, //Don't encode and parse downloaded data as JSONe
        BodyRaw = outputToServer
    }); ;

}

[Serializable]
public class TestDeck
{
    [field: SerializeField]
    public int id { get; set; }
    [field: SerializeField]
    public string deckName { get; set; }
    [field: SerializeField]
    public int deckNumCards { get; set; }
    [field: SerializeField]
    public int deckCreatedBy { get; set; }

    public string deckCardJson { get; set; }
    public string deckDescription { get; set; }

    public string deckImageID { get; set; }

}

}`

jdnichollsc commented 2 years ago

Hello mate, I think you have a concept problem, what are you going to do with the response?

It looks like you're trying to use a synchronous logic with an asynchronous request, that is not allowed because it would freeze the entire application. Please attach a reproducible demo to understand better your scenario.

Best, Juan