How to execute a receive request using RestSharp?

I find it difficult to understand how to make a GET request using RestSharp on Windows Phone 7. All the examples show that you are doing a POST request, but I just need a GET. How to do it?

+6
source share
2 answers

What you are looking for is here .

The following is a snippet of code that covers your script ( request.Method must be set to Method.GET ):

 public void GetLabelFeed(string label, Action<Model.Feed> success, Action<string> failure) { string resource = "reader/api/0/stream/contents/user/-/label/" + label; var request = GetBaseRequest(); request.Resource = resource; request.Method = Method.GET; request.AddParameter("n", 20); //number to return _client.ExecuteAsync<Model.Feed>(request, (response) => { if (response.ResponseStatus == ResponseStatus.Error) { failure(response.ErrorMessage); } else { success(response.Data); } }); } 
+2
source

GET is the default method used by RestSharp, so if you do not 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"); 

What does http://example.com/api?foo=bar mean

+16
source

Source: https://habr.com/ru/post/894655/


All Articles