【发布时间】:2016-11-04 10:56:05
【问题描述】:
我有一个使用 ASP.NET Web API 的 API,它返回一个 json 列表并在 .NET 平台上接收一个 POST 或 GET 我使用类似的东西:
private string UrlLocalTest = "http://192.168.0.102:3000/api/";
public async Task<HttpResponseMessage> PostWeb(Model model)
{
HttpClient client = new HttpClient();
Uri url = new Uri(string.Concat(Url, "gone/POST"));
return await client.PostAsJsonAsync(url, model);
}
public async Task<HttpResponseMessage> GET(string name)
{
var client = new HttpClient();
Uri url = new Uri(string.Concat(UrlLocalTestTwo, "/GET" + name));
var response = await client.GetAsync(url);
return response;
}
并使用oauth2 从我的 WebApi 返回一个令牌,如下所示:
public async Task<HttpResponseMessage> Authenticate(string pEmail = null, string pPassword = null)
{
var Client = new HttpClient();
var _tokenArgs = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("username",pEmail),
new KeyValuePair<string, string>("password",pPassword),
new KeyValuePair<string, string>("grant_type","password")
});
Uri url = new Uri(UrlLocalTest);
return await Client.PostAsync(url, _tokenArgs);
}
如何使用 Android 执行这些方法和操作?我找到了接近 this 的东西,但我相信在 Android 上更复杂。
【问题讨论】:
标签: java android android-studio