Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform a get request with RestSharp?

I'm having trouble figuring out how to make a GET request using RestSharp on Windows Phone 7. All of the examples show making a POST request, but I just need GET. How do I do this?

like image 563
Christopher Avatar asked Aug 09 '11 16:08

Christopher


1 Answers

GET is the default method used by RestSharp, so if you don't specify a method, it will use GET:

var client = new RestClient("http://example.com");
var request = new RestRequest("api");

client.ExecuteAsync(request, response => {
    // do something with the response
});

This code will make a GET request to http://example.com/api. If you need to add URL parameters you can do this:

var client = new RestClient("http://example.com");
var request = new RestRequest("api");    
request.AddParameter("foo", "bar");

Which translates to http://example.com/api?foo=bar

like image 93
John Sheehan Avatar answered Dec 10 '22 04:12

John Sheehan