question

cainlaikind avatar image
cainlaikind asked

Deserialize loginResult from c# httpClient.postAsync

Hello I'm very new to networking and I'm wondering if anyone knows how I might get at the LoginResult from a successful login using System.net HttpClient?

        StringContent queryString = new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
         string emailurl = "https://titleId.playfabapi.com/Client/LoginWithEmailAddress";
        
          var response = await client.PostAsync(emailurl,queryString);
          var responseBody = await response.Content.ReadAsStringAsync();
         
         LoginResult loginresult = JsonConvert.DeserializeObject{LoginResult}(responseBody);
         if (response.IsSuccessStatusCode)
     {
         Debug.WriteLine("http success: " + responseBody);
         Debug.WriteLine("Session ticket: " + result.SessionTicket);

         OnLoginSuccess(loginresult);
 }

http success: {"code":200,"status":"OK","data":{"SessionTicket":"653F511587887FAB.......

Session ticket:

^The problem is LoginResult does not deserialize properly (all the fields, such as session ticket, are empty) and I don't know how to get the sessionTicket from code. And I need to sessionTicket to get user data.

^I believe "data" is the actual LoginResult that I'm looking for. But I don't know what the type of what I'm actually getting is?

Player DataAccount Management
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Infer Wang avatar image
Infer Wang answered

You may use the c# SDK. Quickstart - PlayFab Client library for C# - PlayFab | Microsoft Learn This will help handle deserializing and store the sessionticket for further calls.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.