小编Rom*_*maS的帖子

RestSharp HttpBasicAuthentication - 示例

我有一个使用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)
  1. 如何Authorization: Basic YWRtaW46MjI=在服务器端处理此字段?我从这个标题中获取用户名和密码吗?
  2. 如何将安全令牌从服务器返回到客户端并将其保存在客户端?

我需要基于安全令牌进行简单的身份验证,但找不到描述此过程所有方面的示例.有人能指出我的一些完整的例子,包括客户端和服务器端(并使用RestSharp).

c# authentication restsharp

16
推荐指数
4
解决办法
3万
查看次数

标签 统计

authentication ×1

c# ×1

restsharp ×1