0
如何根據我的Web API代碼使用Windows Phone執行GET?爲了發佈我已經知道並適用於我的帖子,但我不知道從我的API中檢索收藏列表,謝謝!如何使用WebApi獲取Windows Phone 8.1上的列表
我API代碼:
public class UsersController : ApiController
{
private ApiDatabaseEntities data = new ApiDatabaseEntities();
public IHttpActionResult GetUsuarios()
{
try
{
IEnumerable<Usuario> usuarios = data.Usuario.AsEnumerable();
return Ok(usuarios.AsEnumerable());
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
public IHttpActionResult PostUsuarios(Usuario usuario)
{
try
{
data.Usuario.Add(usuario);
data.SaveChanges();
return Ok();
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
這裏是我的Windows電話代碼:
1 - WebApiBase
public abstract class WebApiBase<T>
{
private string Url = "http://localhost:63964/api/users";
protected virtual void Post(object objectPost)
{
HttpClient client = new HttpClient();
client.PostAsJsonAsync(Url, objectPost);
}
public abstract void Send(T objectPost);
}
2 - 而UsuarioApi
public class UsuarioApi : WebApiBase<Models.UserPhone>
{
public override void Send(UserPhone objectPost)
{
this.Post(objectPost);
}
}