文章出處
文章列表
一、XUtils lib的的添加:
1、點擊+,選擇第一個Library dependency
2、輸入XUtils 按enter鍵,搜索:
3、然后就是選擇XUtils,選擇哪個版本就看個人了,接著點擊ok-->ok,程序開始重新編譯。
4、以HTTP請求為例:
1 private void getDataFromServer(){ 2 HttpUtils utils = new HttpUtils(); 3 utils.send(HttpRequest.HttpMethod.GET, GlobalConstants.GATEGORY_URL, new RequestCallBack<String>() { 4 @Override//請求成功 5 public void onSuccess(ResponseInfo<String> responseInfo) { 6 String result = responseInfo.result; 7 System.out.println("result: "+result); 8 9 } 10 @Override//請求失敗 11 public void onFailure(HttpException error, String msg) { 12 13 } 14 }); 15 16 }
上面的請求可能會報錯,錯誤如下:
當遇到上面的錯誤是,你需要在build.gradle文件中添加一行代碼(useLibrary 'org.apache.http.legacy'):
然后再編譯就沒問題了。
文章列表
全站熱搜