Amit Joshi

Amit Joshi

  • NA
  • 2
  • 7k

Xamarin Forms HttpClient not working

Nov 23 2016 11:59 PM
Hi,
 
I am new to Xamarin Cross-Flatform technology (C#). I am developing one small application where I need to call the http url, get the json data, parse it and display it on the screen.
 
I am using System.Net.Http for achieving the http call. Below is the code i am using to achieve it.
But request is not reaching to http url
 
namespace EmployeeInfo
{
class HttpCommunicator
{
public async Task<RootObject> sendRequest()
{
RootObject rootObject = new RootObject();
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://192.168.1.36:8080/JsonReader/JsonReader");
var result = await client.SendAsync(request);
result.EnsureSuccessStatusCode();
var content = await result.Content.ReadAsStringAsync();
//client.BaseAddress = new Uri("http://172.19.4.176:8080/JsonReader/JsonReader");
//var response = await client.GetAsync("http://172.19.4.176:8080/JsonReader/JsonReader");
//var placesJson = response.Content.ReadAsStringAsync().Result;
if ( null != content)
{
rootObject = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(content);
}
return rootObject;
}
}
}
 

Answers (1)