[英]What is the proper way to use basic authentication?
I am pretty much new to RestSharp and am bit confused about the below two code blocks (numbered). 我对RestSharp相当陌生,对以下两个代码块(编号)感到有些困惑。
var client = new RestClient("url"); // client
client.Authenticator = new HttpBasicAuthenticator("username", "password");
var request = new RestRequest(Method.GET); request.AddHeader("authorization", string.Format("Basic {0}", "username:password"));
IRestResponse response = client.Execute(request);
when to use authentication in client
section and when to use it in request
section. 何时在
client
部分使用身份验证以及何时在request
部分使用身份验证。 If we add basic authenticator in client object itself then is it required to bind it in every request that we make? 如果我们在客户端对象本身中添加基本身份验证器,那么是否需要将其绑定到我们提出的每个请求中?
It would be helpful if someone can explain or direct me to right contents. 如果有人可以向我解释或指导我正确的内容,这将很有帮助。
when to use authentication in client section
客户端部分何时使用身份验证
When you use one client to issue multiple requests that all need the same authorization. 当您使用一个客户端发出多个都需要相同授权的请求时。
and when to use it in request section.
以及何时在请求部分使用它。
When you want to issue a single request that requires authorization. 当您要发出需要授权的单个请求时。
If we add basic authenticator in client object itself then is it required to bind it in every request that we make?
如果我们在客户端对象本身中添加基本身份验证器,那么是否需要将其绑定到我们提出的每个请求中?
No. 没有。
See also Authenticators on RestSharp's GitHub Wiki . 另请参阅RestSharp的GitHub Wiki上的身份验证器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.