微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin.forms登录后获取令牌

如何解决Xamarin.forms登录后获取令牌

对不起,我的语言不好。我想知道在登录xamarin.forms后如何获取令牌。我在邮递员中输入我的电子邮件和密码,它会生成底部可见的令牌

enter image description here

我通过输入Bearer +令牌来授权自己

enter image description here

解决方法

您可以使用HttpClient来Consume a RESTful Web Service并从响应中获取令牌:

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);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。