Connection with Web Api

ShahulShahul INMember ✭✭

public async Task<List> GetLocation(TodoItem notes)
{
var lst = new List();

        try
        {

            var json = JsonConvert.SerializeObject(notes);
            var content = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.GetAsync("http://192.168.1.55:85/api/Database/GetEmpGender_GP/?employid=acke0001");
            await Task.Delay(5000);
            if (response.IsSuccessStatusCode)
            {

                var users = await response.Content.ReadAsStringAsync();
                lst = JsonConvert.DeserializeObject<List<TodoItem>>(users);
            }
            return lst;
        }
        catch (TaskCanceledException timeoutEx)
        {
            System.Diagnostics.Debug.WriteLine(timeoutEx);
            return null;
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Error {0}", ex.Message);
            return null;
        }
    }

This is my code above. Am not able to connect with the link and retrieve data's. Please help me

Best Answers

Answers

  • TonyDTonyD USMember ✭✭✭

    What error do you get? I think the latest iOS only allows https unless you put an exception in info.plist

  • ShahulShahul INMember ✭✭

    @xami3 : Thanks for your help. i was getting error while connecting the error .. "An error occurred while sending the request".. please help me

  • VenkataSivaprasadReddyPulagamVenkataSivaprasadReddyPulagam USMember ✭✭✭
    edited June 2017

    Hi Shahul,

    try using this line before sending request
    client.DefaultRequestHeaders.Accept.Add (new MediaTypeWithQualityHeaderValue("application/json"));

    ThankYou.

Sign In or Register to comment.