我有一个使用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);
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
Authorization: Basic YWRtaW46MjI=在服务器端处理此字段?我从这个标题中获取用户名和密码吗?我需要基于安全令牌进行简单的身份验证,但找不到描述此过程所有方面的示例.有人能指出我的一些完整的例子,包括客户端和服务器端(并使用RestSharp).