CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2013
    Posts
    6

    [RESOLVED] Authentication using RestSharp

    Hi,

    I can't figure out how to make a call to a rest api as authenticated user.

    Code:
    RestClient client = new RestClient("http://www.newsblur.com");
                RestRequest login = new RestRequest("/api/login", Method.POST);
                login.AddParameter("username", "xxxxxxx");
                login.AddParameter("password", "xxxxxxx");
    
    //I getting an ok for my login here
                IRestResponse response = client.Execute(login);
                var content = response.Content;
    
                richTextBox1.Text = content;
    
    
                login.Resource = "reader/feeds";
                login.Method = Method.GET;
                
    //How do i make this call as a loggedin user?
                response = client.Execute(login);
    
                richTextBox1.Text = response.Content;
    How do i make the second execute as a logged in user?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Authentication using RestSharp

    You should probably ask for help as recommended on the http://restsharp.org/ site.

  3. #3
    Join Date
    Mar 2013
    Posts
    6

    Re: Authentication using RestSharp

    I Solved it this way.

    Code:
    RestClient client = new RestClient("http://www.newsblur.com");
                
                RestRequest login = new RestRequest("/api/login", Method.POST);
                login.AddParameter("username", "xxxxx");
                login.AddParameter("password", "xxxxx");
    
                IRestResponse response = client.Execute(login);
                CookieContainer cookiecon = new CookieContainer();
    
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var cookie = response.Cookies.FirstOrDefault();
                    cookiecon.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain));
                }
                
                client.CookieContainer = cookiecon;
    
    
                RestRequest feeds = new RestRequest("/reader/feeds", Method.GET);
    
    
                IRestResponse<Classes.FeedData> resp = client.Execute<Classes.FeedData>(feeds);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured