-
April 5th, 2013, 01:09 AM
#1
[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?
-
April 7th, 2013, 07:06 PM
#2
Re: Authentication using RestSharp
You should probably ask for help as recommended on the http://restsharp.org/ site.
-
April 8th, 2013, 03:12 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|