15的時候谷歌推薦了一款很牛逼的網絡請求框架okHttp,隨着httpclient的過時使用這款框架變得更爲重要,然而這款牛逼的框架對我們來說設置較多,僅用很小的一部分就能滿足我們的日常開發,基於這個思想,我對okHttp進行了二次封裝,希望能夠幫助大家更好的理解okHttp.
使用幫助
**獲取Person對象**
public void getPerson(){
HashMap<String ,String>params=new HashMap<String,String>();
params.put("type","1");
params.put("time","2016/10/15");
HttpRequest.postRequest(context, "http://test/person", params,
new ModleRequest<Person>(Person.class) {
@Override
protected void onSucess(Person person) {
Message msg=Message.obtain();
msg.obj=person;
msg.what=1;
myHandler.sendEmptyMessage(1);
}
@Override
protected void onFaild(Exception e) {
}
});
}
上傳文件
public void upLoadFile(){
HashMap<String ,String>params=new HashMap<String,String>();
params.put("type","1");
params.put("time","2016/10/15");
File file= FileUtil.creatFile("app/test","dashen.jpj");
HttpRequest.uploadFile("http://test/person", context, params, file, new StringRequest() {
@Override
protected void onSucess(String str) {
}
@Override
protected void onFaild(Exception e) {
}
});
}
代碼就不貼了,快下班了,有需要的問我要
QQ小號1808732263