C
C#2mo ago
charon

Help with request in wpf

Hi so im making this post request to get token from body but i just want to set that response as text in wpf so i just test it works
string json = JsonConvert.SerializeObject("{\"type\":\"email\",\"username\":\"tropeal21@gmail.com\",\"password\":\"Test123!\"}");
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
var httpResponse = await client.PostAsync("https://api.staging.pentagon.games/user/login", httpContent);
var responseString = await httpResponse.Content.ReadAsStringAsync();
BarkinCraft.info = responseString;
string json = JsonConvert.SerializeObject("{\"type\":\"email\",\"username\":\"tropeal21@gmail.com\",\"password\":\"Test123!\"}");
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
var httpResponse = await client.PostAsync("https://api.staging.pentagon.games/user/login", httpContent);
var responseString = await httpResponse.Content.ReadAsStringAsync();
BarkinCraft.info = responseString;
so it gets repsonse and sets it in this info variable so it can be used in main BarkinCraft class where it is set as text of label in gui on form load just to test response
2 Replies
reflectronic
reflectronic2mo ago
you have not actually asked a question, or said what the problem is (i'm assuming it doesn't work) but, i can already something that's almost certainly an issue the string you are passing to JsonConvert.SerializeObject is already JSON, you do not need to "serialize" it again
charon
charon2mo ago
problem wasnt it that but managed to fix it