我真的是新的Xamarin開發,我只是試圖Xamarin.Forms開發Android共享代碼的iOS應用程序&,我在這裏要做的是使用Plugin.RestClient NuGet包從API獲取數據。Xamarin HttpClient.GetStringAsync不工作Xamarin.Droid
這是我的MainViewModel。
public MainViewModel(){
InitializeDataAsync();
}
public async Task InitializeDataAsync(){
var employeeServices = new EmployeeServices();
EmployeesList = await employeeServices.getEmployeesAsync();
}
這是我的服務
public async Task<List<Employee>> getEmployeesAsync(){
RestClient<Employee> restClient = new RestClient<Employee>();
var employeeList = await restClient.GetAsync("http://localhost:3000/employee");
return employeeList;
}
這是我的RESTClient實現
public async Task<List<T>> GetAsync(string WebServiceUrl){
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(WebServiceUrl);
Debug.WriteLine(WebServiceUrl);
Debug.WriteLine(json);
var taskModels = JsonConvert.DeserializeObject<List<T>>(json);
return taskModels;
}
的代碼工作正常,在我的iPhone模擬器。我可以看到我的調試url和json響應。但在我的Android模擬器上,列表中沒有任何內容。我甚至找不到我的調試url和json響應,我已經檢查了我的應用程序輸出和我的設備日誌(我使用Xamarin Studio for Mac btw)。
我也已經在Android Manifest上添加了互聯網權限。 我該怎麼辦?