我有一个使用RestSharp和WEB API服务的WPF客户端。我尝试按照以下方式使用HttpBasicAuthenticator
:
我有一个使用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)。