Skip to content

Commit

Permalink
更新说明书
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Aug 14, 2018
1 parent 5d2a76a commit 323bfc5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ CacheMode | CacheMode | CacheMode.NO_CACHE | 设置请求的缓存模式

构建一个XHttpProxy,将定义的api接口传入后,直接调用接口进行请求。

构造XHttpProxy需要传入`ThreadType`,默认是`ThreadType.TO_MAIN`
构造XHttpProxy可以传入`isPostJson`来决定请求是上传json数据还是键值对数据, 默认是`true`,上传json数据。

构造XHttpProxy可以传入`ThreadType`,默认是`ThreadType.TO_MAIN`

* TO_MAIN: executeToMain(main -> io -> main)

Expand Down Expand Up @@ -699,9 +701,11 @@ XHttp.get("/test/testCustomResult")
public void onSuccess(Boolean response) throws Throwable {
ToastUtils.toast("请求成功:" + response);
}
}){});
}){}); //千万注意,这里的{}一定不能去掉,否则解析错误
```

【注意】上面提示的{}一定不能去掉,否则解析错误, 会报"ApiResult.class.isAssignableFrom(cls) err!!"的错误。

如果你觉得写一长串比较麻烦,你可以自定义请求继承你需要的请求方式,例如这里是get请求,我们可以这样写:

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.xuexiang.xhttp2.exception.ApiException;
import com.xuexiang.xhttp2.logs.HttpLog;
import com.xuexiang.xhttp2.model.ApiResult;
import com.xuexiang.xhttp2.utils.TypeUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Collections;
import java.util.List;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
* 类型工具类
Expand Down Expand Up @@ -137,7 +137,7 @@ private static Type getType(Type type, int i) {
public static <R> Type findNeedType(Class<R> cls) {
List<Type> typeList = TypeUtils.getAllTypes(cls);
if (typeList == null || typeList.isEmpty()) {
return RequestBody.class;
return ResponseBody.class;
}
return typeList.get(0);
}
Expand Down

0 comments on commit 323bfc5

Please sign in to comment.