How to call web api? RRS feed

  • Question

  • User-353733005 posted


    I'm new in web api. I want to call a get method web api which will redirect to the another page which I provide in the query parameter "redirect_uri". In the api have some query parameter. the problem is I don't understand how to call that api with the parameter.

    Here is the sample of the api with query parameter:

    Can anyone help me please. 

    Thanks in advance.

    Monday, November 18, 2019 5:56 AM

All replies

  • User1120430333 posted

    HTTPClient() is the defacto.


    public List<DtoArticle> GetArticlesByAuthorId(int id)
                var dtoarticles = new List<DtoArticle>();
                using (var client = new HttpClient())
                    var uri = new Uri("http://localhost/WebAPI/api/article/GetArticlesByAuthorId?id=" + id);
                    var response = client.GetAsync(uri).Result;
                    if (!response.IsSuccessStatusCode)
                        throw new Exception(response.ToString());
                    var responseContent = response.Content;
                    var responseString = responseContent.ReadAsStringAsync().Result;
                    dynamic articles = JArray.Parse(responseString) as JArray;
                    foreach (var obj in articles)
                        DtoArticle dto = obj.ToObject<DtoArticle>();
                return dtoarticles;

    Monday, November 18, 2019 8:01 AM