I want to call web api(which is on my local visual studio) through Xamarin forms but its not calling my web api. I am using visual studio android emulator.
I am using visual studio 2015 update 3 and here is my code
public class DataService
{
HttpClient client = new HttpClient();
string apiPaht = "http://10.0.2.2:19367/api/";
//string apiPaht = "http://localhost:19367/api/";
public async Task<List<CustomerApp>> GetTodoItemsAsync()
{
var response = await client.GetStringAsync(apiPaht+ "APICustAccount/getTestData");
var todoItems = JsonConvert.DeserializeObject<List<CustomerApp>>(response);
return todoItems;
}
}
Code on my xamal.cs
async void RefreshData()
{
List<CustomerApp> listCust = await _dService.GetTodoItemsAsync();
todoList.ItemsSource = listCust;
string aa = "";
}
protected void btn_click(object sender, EventArgs e)
{
RefreshData();
}
<uses-permission android:name="android.permission.INTERNET" />
in the AndroidManifest.xml – Tamás Szabó