restsharp make multi async requestHow to use RestSharp with async/awaitHow to make HTTP POST web requestAre these the main differences between RestSharp and ServiceStack's Client Code?How and when to use ‘async’ and ‘await’How to use RestSharp with async/awaitfacebook error An active access token must be used to query information about the current userFileNotFoundException on RestSharpCan I set a custom JsonSerializer to RestSharp RestClientHow to use OAuth2 with Restsharp for Lulu APIPersist client session RestSharp for API consumptionStatusCode: InternalServerError, Content-Type: text/html; charset=utf-8, Content-Length: -1 on a POST request

A player is constantly pestering me about rules, what do I do as a DM?

Why aren't (poly-)cotton tents more popular?

Why do some games show lights shine through walls?

Should I tell my insurance company I'm making payments on my new car?

What are the penalties for overstaying in USA?

A parasitic apple tree?

Story-based adventure with functions and relationships

How can I get more energy without spending coins?

How to append a matrix element by element

How come I was asked by a CBP officer why I was in the US?

Is adding a new player (or players) a DM decision, or a group decision?

5 cars in a roundabout traffic

Animation advice please

How can I repair scratches on a painted French door?

Why is C++ initial allocation so much larger than C's?

How well known and how commonly used was Huffman coding in 1979?

Would a two-seat light aircaft with a landing speed of 20 knots and a top speed of 180 knots be technically possible?

What is the fibered coproduct of abelian groups?

No IMPLICIT_CONVERSION warning in this query plan

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

C-152 carb heat on before landing in hot weather?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

How to perform Login Authentication at the client-side?

Are Finite Automata Turing Complete?



restsharp make multi async request


How to use RestSharp with async/awaitHow to make HTTP POST web requestAre these the main differences between RestSharp and ServiceStack's Client Code?How and when to use ‘async’ and ‘await’How to use RestSharp with async/awaitfacebook error An active access token must be used to query information about the current userFileNotFoundException on RestSharpCan I set a custom JsonSerializer to RestSharp RestClientHow to use OAuth2 with Restsharp for Lulu APIPersist client session RestSharp for API consumptionStatusCode: InternalServerError, Content-Type: text/html; charset=utf-8, Content-Length: -1 on a POST request






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















it's easy to request an API with restsharp.org,
but when i need to call two different API, first request holds code, and after response second one starts, i think it is not correct,
below is my code:



var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");
IRestResponse hotels = client.Execute(requestHotels);
List<Hotel> topHotels = JsonConvert.DeserializeObject<List<Hotel>>(hotels.Content);

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");
IRestResponse cities = client.Execute(requestCities);
List<City> topCities = JsonConvert.DeserializeObject<List<City>>(cities.Content);


as you see city request wait until hotel request response, but i think both of them must be send, and wait until both response come back.



how can i do this like?










share|improve this question






















  • You can use ExecuteAsync or ExecuteTaskAsync methods instead of Execute.

    – Wokuo
    Mar 25 at 10:28











  • @Wokuo how? in example there is no multi request, how i understand both of request are done?

    – mohammad adibi
    Mar 25 at 10:32






  • 1





    This is not specifically for RestSharp but you can apply it. You have to understand async/await in order to use the suggested ExecuteAsync method of RestSharp.

    – Crowcoder
    Mar 25 at 11:44

















2















it's easy to request an API with restsharp.org,
but when i need to call two different API, first request holds code, and after response second one starts, i think it is not correct,
below is my code:



var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");
IRestResponse hotels = client.Execute(requestHotels);
List<Hotel> topHotels = JsonConvert.DeserializeObject<List<Hotel>>(hotels.Content);

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");
IRestResponse cities = client.Execute(requestCities);
List<City> topCities = JsonConvert.DeserializeObject<List<City>>(cities.Content);


as you see city request wait until hotel request response, but i think both of them must be send, and wait until both response come back.



how can i do this like?










share|improve this question






















  • You can use ExecuteAsync or ExecuteTaskAsync methods instead of Execute.

    – Wokuo
    Mar 25 at 10:28











  • @Wokuo how? in example there is no multi request, how i understand both of request are done?

    – mohammad adibi
    Mar 25 at 10:32






  • 1





    This is not specifically for RestSharp but you can apply it. You have to understand async/await in order to use the suggested ExecuteAsync method of RestSharp.

    – Crowcoder
    Mar 25 at 11:44













2












2








2








it's easy to request an API with restsharp.org,
but when i need to call two different API, first request holds code, and after response second one starts, i think it is not correct,
below is my code:



var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");
IRestResponse hotels = client.Execute(requestHotels);
List<Hotel> topHotels = JsonConvert.DeserializeObject<List<Hotel>>(hotels.Content);

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");
IRestResponse cities = client.Execute(requestCities);
List<City> topCities = JsonConvert.DeserializeObject<List<City>>(cities.Content);


as you see city request wait until hotel request response, but i think both of them must be send, and wait until both response come back.



how can i do this like?










share|improve this question














it's easy to request an API with restsharp.org,
but when i need to call two different API, first request holds code, and after response second one starts, i think it is not correct,
below is my code:



var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");
IRestResponse hotels = client.Execute(requestHotels);
List<Hotel> topHotels = JsonConvert.DeserializeObject<List<Hotel>>(hotels.Content);

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");
IRestResponse cities = client.Execute(requestCities);
List<City> topCities = JsonConvert.DeserializeObject<List<City>>(cities.Content);


as you see city request wait until hotel request response, but i think both of them must be send, and wait until both response come back.



how can i do this like?







c# restsharp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 10:25









mohammad adibimohammad adibi

133 bronze badges




133 bronze badges












  • You can use ExecuteAsync or ExecuteTaskAsync methods instead of Execute.

    – Wokuo
    Mar 25 at 10:28











  • @Wokuo how? in example there is no multi request, how i understand both of request are done?

    – mohammad adibi
    Mar 25 at 10:32






  • 1





    This is not specifically for RestSharp but you can apply it. You have to understand async/await in order to use the suggested ExecuteAsync method of RestSharp.

    – Crowcoder
    Mar 25 at 11:44

















  • You can use ExecuteAsync or ExecuteTaskAsync methods instead of Execute.

    – Wokuo
    Mar 25 at 10:28











  • @Wokuo how? in example there is no multi request, how i understand both of request are done?

    – mohammad adibi
    Mar 25 at 10:32






  • 1





    This is not specifically for RestSharp but you can apply it. You have to understand async/await in order to use the suggested ExecuteAsync method of RestSharp.

    – Crowcoder
    Mar 25 at 11:44
















You can use ExecuteAsync or ExecuteTaskAsync methods instead of Execute.

– Wokuo
Mar 25 at 10:28





You can use ExecuteAsync or ExecuteTaskAsync methods instead of Execute.

– Wokuo
Mar 25 at 10:28













@Wokuo how? in example there is no multi request, how i understand both of request are done?

– mohammad adibi
Mar 25 at 10:32





@Wokuo how? in example there is no multi request, how i understand both of request are done?

– mohammad adibi
Mar 25 at 10:32




1




1





This is not specifically for RestSharp but you can apply it. You have to understand async/await in order to use the suggested ExecuteAsync method of RestSharp.

– Crowcoder
Mar 25 at 11:44





This is not specifically for RestSharp but you can apply it. You have to understand async/await in order to use the suggested ExecuteAsync method of RestSharp.

– Crowcoder
Mar 25 at 11:44












1 Answer
1






active

oldest

votes


















4














The comments are correct, using ExecuteAsync (which can also deserialise the data - see http://restsharp.org/) with Tasks could look something like the following:



// Set up requests as before
var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");

var cancellationTokenSource = new CancellationTokenSource();

var hotelsTask = client.ExecuteTaskAsync<List<Hotel>>(requestHotels, cancellationTokenSource.Token);
var citiesTask = client.ExecuteTaskAsync<List<City>>(requestCities, cancellationTokenSource.Token);

var tasks = new List<Task> hotelsTask, citiesTask ;

// Pause execution here until both tasks are complete
await Task.WhenAll(tasks);

// Check status then use hotelsTask.Result and citiesTask.Result





share|improve this answer

























  • The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

    – mohammad adibi
    Mar 26 at 5:18












  • client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

    – mohammad adibi
    Mar 26 at 8:38












  • I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

    – Greg Stanley
    Mar 26 at 10:41














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335673%2frestsharp-make-multi-async-request%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














The comments are correct, using ExecuteAsync (which can also deserialise the data - see http://restsharp.org/) with Tasks could look something like the following:



// Set up requests as before
var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");

var cancellationTokenSource = new CancellationTokenSource();

var hotelsTask = client.ExecuteTaskAsync<List<Hotel>>(requestHotels, cancellationTokenSource.Token);
var citiesTask = client.ExecuteTaskAsync<List<City>>(requestCities, cancellationTokenSource.Token);

var tasks = new List<Task> hotelsTask, citiesTask ;

// Pause execution here until both tasks are complete
await Task.WhenAll(tasks);

// Check status then use hotelsTask.Result and citiesTask.Result





share|improve this answer

























  • The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

    – mohammad adibi
    Mar 26 at 5:18












  • client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

    – mohammad adibi
    Mar 26 at 8:38












  • I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

    – Greg Stanley
    Mar 26 at 10:41
















4














The comments are correct, using ExecuteAsync (which can also deserialise the data - see http://restsharp.org/) with Tasks could look something like the following:



// Set up requests as before
var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");

var cancellationTokenSource = new CancellationTokenSource();

var hotelsTask = client.ExecuteTaskAsync<List<Hotel>>(requestHotels, cancellationTokenSource.Token);
var citiesTask = client.ExecuteTaskAsync<List<City>>(requestCities, cancellationTokenSource.Token);

var tasks = new List<Task> hotelsTask, citiesTask ;

// Pause execution here until both tasks are complete
await Task.WhenAll(tasks);

// Check status then use hotelsTask.Result and citiesTask.Result





share|improve this answer

























  • The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

    – mohammad adibi
    Mar 26 at 5:18












  • client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

    – mohammad adibi
    Mar 26 at 8:38












  • I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

    – Greg Stanley
    Mar 26 at 10:41














4












4








4







The comments are correct, using ExecuteAsync (which can also deserialise the data - see http://restsharp.org/) with Tasks could look something like the following:



// Set up requests as before
var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");

var cancellationTokenSource = new CancellationTokenSource();

var hotelsTask = client.ExecuteTaskAsync<List<Hotel>>(requestHotels, cancellationTokenSource.Token);
var citiesTask = client.ExecuteTaskAsync<List<City>>(requestCities, cancellationTokenSource.Token);

var tasks = new List<Task> hotelsTask, citiesTask ;

// Pause execution here until both tasks are complete
await Task.WhenAll(tasks);

// Check status then use hotelsTask.Result and citiesTask.Result





share|improve this answer















The comments are correct, using ExecuteAsync (which can also deserialise the data - see http://restsharp.org/) with Tasks could look something like the following:



// Set up requests as before
var client = new RestClient("http://xxx.yyy.com/");

var requestHotels = new RestRequest("api/hotelUi/home/hotelList", Method.POST);
requestHotels.AddParameter("take", "16");

var requestCities = new RestRequest("api/hotelUi/home/cityList", Method.POST);
requestCities.AddParameter("take", "16");

var cancellationTokenSource = new CancellationTokenSource();

var hotelsTask = client.ExecuteTaskAsync<List<Hotel>>(requestHotels, cancellationTokenSource.Token);
var citiesTask = client.ExecuteTaskAsync<List<City>>(requestCities, cancellationTokenSource.Token);

var tasks = new List<Task> hotelsTask, citiesTask ;

// Pause execution here until both tasks are complete
await Task.WhenAll(tasks);

// Check status then use hotelsTask.Result and citiesTask.Result






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 10:35

























answered Mar 25 at 13:07









Greg StanleyGreg Stanley

2451 silver badge8 bronze badges




2451 silver badge8 bronze badges












  • The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

    – mohammad adibi
    Mar 26 at 5:18












  • client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

    – mohammad adibi
    Mar 26 at 8:38












  • I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

    – Greg Stanley
    Mar 26 at 10:41


















  • The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

    – mohammad adibi
    Mar 26 at 5:18












  • client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

    – mohammad adibi
    Mar 26 at 8:38












  • I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

    – Greg Stanley
    Mar 26 at 10:41

















The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

– mohammad adibi
Mar 26 at 5:18






The best overloaded Add method 'List<Task>.Add(Task)' for the collection initializer has some invalid arguments

– mohammad adibi
Mar 26 at 5:18














client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

– mohammad adibi
Mar 26 at 8:38






client.ExecuteTaskAsync(requestHotels , cancellationTokenSource.Token), please complete your answer for others, thank you, stackoverflow.com/a/21779724/11254207

– mohammad adibi
Mar 26 at 8:38














I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

– Greg Stanley
Mar 26 at 10:41






I've changed the example to use the ExecuteAsyncTask approach. I don't have data to test the response but you should be able to inspect the two task objects and find what you need.

– Greg Stanley
Mar 26 at 10:41




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335673%2frestsharp-make-multi-async-request%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현