【发布时间】:2015-10-28 06:48:26
【问题描述】:
我有一个使用 RestSharp 和 WEB API 服务的 WPF 客户端。我尝试如下使用HttpBasicAuthenticator:
RestRequest login = new RestRequest("/api/users/login", Method.POST);
var authenticator = new HttpBasicAuthenticator("admin","22");
authenticator.Authenticate(Client, login);
IRestResponse response = Client.Execute(login);
POST 请求如下所示:
POST http://localhost/api/users/login HTTP/1.1
Authorization: Basic YWRtaW46MjI=
Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
User-Agent: RestSharp/105.1.0.0
Host: dellnote:810
Content-Length: 0
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
- 如何在服务器端处理
Authorization: Basic YWRtaW46MjI=这个字段?我是否从此标题中获取用户名和密码? - 如何将安全令牌从服务器返回到客户端并保存在客户端?
我需要获得基于安全令牌的简单身份验证,但找不到描述此过程各个方面的示例。有人可以指出一些完整的例子,包括客户端和服务器端(并使用 RestSharp)。
【问题讨论】:
标签: c# authentication restsharp