2016-11-04 87 views
-2

消耗问题的REST服务,我有使用ASP.NET的Web API,它返回一个JSON清单和接收,以及,在.NET平台做一个POSTGET我使用的东西像一个API:如何使用Android Studio的

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上更复杂。

回答

1

看一看OkHttp。它提供了对基于HTTP的服务的简单访问,而不需要太多的抽象。为什么你认为在Android上它会更复杂?

+0

谢谢,我会检查这个环节,因为我是从.NET来了,有基本的WPF相同的代码在表单,工作在UWP,我们只需要添加一个参考和做过,但使用android中,我看到的是不同的东西,如Java语言,但不是所有的“普通”Java库上的Java库。谢谢。 –

相关问题