tsy12321 / myokhttp Goto Github PK
View Code? Open in Web Editor NEW对Okhttp3进行二次封装,对外提供了POST请求、GET请求、PATCH请求、PUT请求、DELETE请求、上传文件、下载文件、取消请求、Raw/Json/Gson返回、后台下载管理等功能
License: Apache License 2.0
对Okhttp3进行二次封装,对外提供了POST请求、GET请求、PATCH请求、PUT请求、DELETE请求、上传文件、下载文件、取消请求、Raw/Json/Gson返回、后台下载管理等功能
License: Apache License 2.0
MyOkHttp mMyOkhttp = new MyOkHttp();
mMyOkhttp.upload()
.url(有地址)
.addParam("sid", "2fa35b10-4ec8-4f3d-b808-ba9c1e6a43f5")
.addParam("modelname", "gms")
.addFile("", file)
.tag(this)
.enqueue(new GsonResponseHandler<Response>() {
@Override
public void onFailure(int statusCode, String error_msg) {
Log.i("onFailure", "onFailure: 执行了");
}
@Override
public void onSuccess(int statusCode, Response response) {
Log.i("onSuccess", "onSuccess: 执行了");
}
});
}
public class MyCallback implements Callback {
private IResponseHandler mResponseHandler;
public MyCallback(IResponseHandler responseHandler) {
mResponseHandler = responseHandler;
}
@Override
public void onFailure(Call call, final IOException e) {
LogUtils.e("onFailure", e);
MyOkHttp.mHandler.post(new Runnable() {
@Override
public void run() {
mResponseHandler.onFailure(0, e.toString());
}
});
}
这里的 mResponseHandler.onFailure(0, e.toString());建议不要返回toString ,否则okhttp自己返回的例如SocketTimeOutException异常,返回的msg会把异常类型也打印出来。。
有两个public void onSuccess(int statusCode, JSONObject response) 有什么作用?
C:\Users\CamiXXX\Desktop\Roaming\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\CamiXXX\AppData\Local\Android\Sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1
老板来份同步的代码,ok3同步需要在子线程中开启,这个有点不太明白
// 初始化网络请求
HttpLoggingInterceptor interceptor = new
HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@OverRide
public void log(String message) {
LogUtils.log("NetUtil", message);
}
});
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15,TimeUnit.SECONDS)
.addInterceptor(interceptor).build();
Post enqueue error:unexpected url一直报这个错误,是我的params不对吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.