본문 바로가기

Programming/안드로이드

Json Rest Api

Task.Run(async () =>
            {
                var client = new HttpClient();
                var content = new StringContent(
                    JsonConvert.SerializeObject(new { user = "name", password = "pass" }));

                try {
                    var result = await client.PostAsync("http://192.168.0.1:8080", content).ConfigureAwait(false);
                    if (result.IsSuccessStatusCode)
                    {
                        var tokenJson = await result.Content.ReadAsStringAsync();
                        Debug.WriteLine(tokenJson);
                    }
                }
                catch (Exception _e) {
                    Debug.WriteLine(_e.ToString());
                }
            });