Git Product home page Git Product logo

okhttputils's People

Contributors

bryant1410 avatar duzechao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

okhttputils's Issues

能不能给个例子,如添加拦截器什么的?写的DEMO有点简单了

okHttpUtils = new OKHttpUtils.Builder(this).interceptors(new AgainInterceptor()).build();//这样初始化还不对的,请多多指教

class LoggingInterceptor implements Interceptor {
@OverRide public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
long t1 = System.nanoTime();
System.out.println(String.format("Sending request %s on %s%n%s",
request.url(), chain.connection(), request.headers()));
Response response = chain.proceed(request);
long t2 = System.nanoTime();
System.out.println(String.format("Received response for %s in %.1fms%n%s",
response.request().url(), (t2 - t1) / 1e6d, response.headers()));
return response;
}
}
class AgainInterceptor implements Interceptor {
@OverRide public Response intercept(Interceptor.Chain chain) throws IOException {
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new LoggingInterceptor());
Request request = new Request.Builder()
.url("http://www.publicobject.com/helloworld.txt")
.header("User-Agent", "OkHttp Example")
.build();
Response response = client.newCall(request).execute();
response.body().close();
return response;
}
}

为什么我的直接返回String时无法成功

private Callback Callback1 = new Callback() {
@OverRide
public void onFailure(Call call, IOException e) {
onFail(e);
}

    @Override
    public void onResponse(Call call,final Response response) throws IOException {
        if(response!=null){
            mtvOkHttp.post(new Runnable() {
                @Override
                public void run() {
                    System.out.println(response.body().toString());
                    mtvOkHttp.setText(response.body().toString());
                }

            });
        }
    }
};

返回的结果为:System.out: okhttp3.internal.http.RealResponseBody@41746480
为什么返回不了实际文本内容呢?请楼主多多指教

题主:OkHttp3的cacheControl无效

在OkHttp 2.6 下,
public Builder cacheControl(CacheControl cacheControl) {
String value = cacheControl.toString();
if (value.isEmpty()) return removeHeader("Cache-Control");
return header("Cache-Control", value);
}
设置了策略会覆盖头字段的,所以头字段写缓存字段 没必要。

然后在OkHttp 3.0下
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta3'
compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'

用最新的引用,cacheControl无效,我研究了一下午,题主可以一起研究下

【紧急】去掉了在拦截器添加缓存时间的设置 的一点疑问?

去掉了在拦截器添加缓存时间的设置 ,那缓存是需要服务器来返回响应头吗?响应头的缓存参数由服务器设置。请楼主解答。如果服务器不支持缓存,又不加自定义拦截器设置响应头缓存参数,楼主是靠什么来设置缓存的?具体类代码见:https://github.com/duzechao/OKHttpUtils/blob/master/okhttputilslib/src/main/java/git/dzc/okhttputilslib/OKHttpUtils.java

process stopped due to unexpected signal 13

/git.dzc.okhttputils I/aaaaaa: onResponse upload server is on

                                                       [ 04-01 10:43:16.294  2908: 2908 E/         ]
                                                       process stopped due to unexpected signal 13

上传图片,报这个错:signal 13的意思  #define SIGSEGV   无效内存引用  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.