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 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(content);
}
return rootObject;
}
}
}
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rupesh KahanePosted Nov 25, 2016, 7:04 AM
if you are using any Web Service for your App then do not forget to give permissions to access Internet.
Steps:
1. Right-click on your android project and select Properties.
2. Select Android Manifest in the window that opens.
3. Check the permission that you want to require in the list of permissions i.e check the checkbox of "Internet"