Good afternoon. I'm trying to get a list of users from the site (let it be example.com \ users) (using RestSharp, but in general it would only become clear at last), and for this you first need to drive the search data into the selector. It looks like a piece of page code like this:

<select name="search_users" id="search_users_id"> <option value="" selected="selected">Select a country</option> <option value="1">Russia</option> 

And despite the long reading of various resources, I still can not understand - how to throw the desired value of "Russia" as the selected one? I understand that you need to send something like

 <select name="search_users" id="search_users_id"> <option value="">Select a country</option> <option value="1" selected="selected">Russia</option> 

But how is that specific? All that I find lately is either examples of "How to get the code for the page" (although I still understand how to get the code for the RestSharp page), or something that is understandable to people already passing by. Thank :)

    1 answer 1

    It's not a matter of restsharp, you don't have a general understanding of web technologies.

    Suppose there is some web page that displays a list of users of a particular country, depending on the selected filter:

     <form method="post"> <select name="country"> <option value="">Select a country</option> <option value="1">Russia</option> <option value="2">USA</option> </select> ..... <button type="submit">Filter</button> </form> 

    It doesn’t matter whether you use a browser or restsharp - the whole bitter will not go to the server anymore from select - option - option and so on. The country variable and its value are passed to the server, for example, 1 or 2.

    Conveniently this can be shown on the pages of get-requests. For example, if the parameter would be method = 'get' in this form, then the browser would go to the example.com \ users? Country = 1 page (depending on what you chose), well, to be more precise - then the page that is defined in the action form.

    Thus, an exemplary fragment through RestSharp will be like this:

     var restClient = new RestClient("https://example.com"); var request = new RestRequest(Method.POST); request.Resource = "/users"; request.AddParameter("search_users", 1); // Тут могут быть ещё параметhы: request.AddParameter("param", "value"); var response = restClient.Execute(request);