Sorry for my poor language. I would like to know how to get the token after logging in in xamarin.forms. I enter my email and password in postman, it generates the token visible at the bottom

            Asked
            
        
        
            Active
            
        
            Viewed 82 times
        
    1
            
            
         
    
    
        ReVoPEP
        
- 29
- 5
- 
                    Would [this Q](https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c) help? – Shaw Nov 11 '20 at 01:16
- 
                    it appears the token is returned in the response body – Jason Nov 11 '20 at 01:16
- 
                    Xamarin.Essentials WebAuthenticator/OAuth2 https://learn.microsoft.com/en-us/xamarin/essentials/web-authenticator?tabs=ios#using-webauthenticator – SushiHangover Nov 11 '20 at 01:16
1 Answers
1
            You can use HttpClient to Consume a RESTful Web Service and get the token from the response:
public async void test() {
    var client = new HttpClient();
    string jsonData = @"{""username"" : ""myusername"", ""password"" : ""mypassword""}";
    var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
    HttpResponseMessage response = await client.PostAsync("your request url", content);
    // this result string should be something like: "{"token":"rgh2ghgdsfds"}"
    var result = await response.Content.ReadAsStringAsync();
    Console.WriteLine(result);
}
 
    
    
        nevermore
        
- 15,432
- 1
- 12
- 30
- 
                    I want to format this line of code so that "email.Text" is in quotation marks, but so that I can also enter text for this: string jsonData = @"{""username"" : ""myusername"", ""password"" : ""mypassword""}"; – ReVoPEP Nov 12 '20 at 21:31
- 
                    
- 
                    If my solution works for you, can you please accept both answer (click the ☑️ in the upper left corner of this answer ) so that we can help more people with same problem:). – nevermore Nov 13 '20 at 01:53
