What is the best way to make HttpWebRequests to an existing Api in xamarin.forms

I am developing an app for users to get information about store promotions/sales. There is already an existing API with all the relevant methods needed for the app functionality. I have minimal experience with WebApi's so will just appreciate advice/guidelines on the best approach to make HttpWebRequests to this existing Api using xamarin.forms. Thanks :)

Answers

  • Gigex42Gigex42 USMember ✭✭✭✭

    Im using this:

    using (HttpClient client = new HttpClient())
    {
    using (HttpResponseMessage response = await client.PostAsync(reqstring, cont))
    {
    if (response.StatusCode != System.Net.HttpStatusCode.OK)
    return null;
    
                        using (HttpContent content = response.Content)
                        {
                            string result = await content.ReadAsStringAsync();
                            var Settings = JsonConvert.DeserializeObject(result);
                            return Settings;
                        }
                    }
                }
    

    reqstring is you requeststring and cont can be your parameter passing to the service.

    But seeing this post there sems to be a problem with the httpclient within a using statement.

Sign In or Register to comment.