RestSharp HttpBasicAuthentication - example

后端 未结 5 1497
梦毁少年i
梦毁少年i 2021-01-03 20:51

I have a WPF client using RestSharp and WEB API Service. I try to use HttpBasicAuthenticator as follows:

RestRequest login = new RestRequest(\"/         


        
5条回答
  •  [愿得一人]
    2021-01-03 21:44

    From RestSharp documentation:

    var client = new RestClient("http://example.com");
    client.Authenticator = new SimpleAuthenticator("username", "foo", "password", "bar");
    
    var request = new RestRequest("resource", Method.GET);
    client.Execute(request);
    

    The URL generated for this request would be http://example.com/resource?username=foo&password=bar

    So you get the password just as any other parameter (although, it's recommended to use POST method then GET, for security reasons).

    As for the cookies, check this out: https://msdn.microsoft.com/en-us/library/system.windows.application.setcookie.aspx

    https://msdn.microsoft.com/en-us/library/system.windows.application.getcookie.aspx

    Hope it helps

提交回复
热议问题