1
我想通過Xamarin來調用Web API(這是我本地視覺工作室)形成 ,但它不是叫我的網頁API。我正在使用Visual Studio的Android模擬器。xamarin形式沒有要求使用Visual Studio的網頁API 2105
我使用的Visual Studio 2015年更新3,這裏是我的代碼
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;
}
}
代碼我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();
}
您的應用程序有互聯網的權限?一世。即'<使用許可權的android:name =「android.permission.INTERNET對」 />'在AndroidManifest.xml –
你能達到從仿真瀏覽器的網址? –
是的,我已經上網權限@tamas薩博 – satyender