okhttp

Is Retrofit+Okhttp using httpCaching as a default in Android?

房东的猫 提交于 2019-12-18 10:56:25
问题 I use retrofit and okhttp in one of our applications. I can't really find a good explanation for the default behaviour of Retrofit. If Okhttp is on the class path it will be automatically used. But as far as I can see it the default HttpResponseCache is null. Do I need to explicitly enable caching with Retrofit and Okhttp? 回答1: You should manually create your OkHttpClient and configure it how you like. In this case you should install a cache. Once you have that create an OkClient and pass it

Android常见问题简单总结

纵然是瞬间 提交于 2019-12-18 10:46:52
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、 https,如何避免Client和Server中间劫持? 客户端是如何校验证书的呢?这里发生在第三步,客户端接收到服务端的证书,里面主要包含公钥和签名。根据证书上的签发机构去浏览器内置的CA签发证书里面找到保存的证书公钥,然后用这个公钥解开签名,得到数字摘要(digest,证书内容的hash值),和服务端的证书进行对比验证。 所以https可以被拦截,但是不能被劫持。 二、 插件化hook IActivityManager采用什么代理方式?为什么? ** hook IActivityManager是采用动态代理的方式。因为它并没有一个具体的实现类,而是使用代理的方式。 三、 找车App白屏问题,内存泄漏 找车app是汽车之家主app里面很重要的一个模块,在无网络的情况下也需要能够展示默认数据。这些默认数据会在app第一次启动的时候需要序列化到数据库里面,由于在主线程做的会有一会儿白屏。 需要把这个序列化放在后端做处理,这里我用AsyncTask,在后端去做处理。但是这里如果匿名内部类会有持有Activity的引用,这样如果退出Activity后台操作还没有处理完成,那么activity就没法被回收,会有内存泄漏问题。 这里使用静态内部类来解决这个问题

Retrofit POST request w/ Basic HTTP Authentication: “Cannot retry streamed HTTP body”

妖精的绣舞 提交于 2019-12-18 10:20:09
问题 I'm using Retrofit to do a basic POST request, and I'm providing a basic @Body for the request. @POST("/rest/v1/auth/login") LoginResponse login(@Body LoginRequest loginRequest); When I'm building the interface for Retrofit I'm providing my own custom OkHttpClient, and all that I'm doing to it is adding my own custom authentication: @Provides @Singleton public Client providesClient() { OkHttpClient httpClient = new OkHttpClient(); httpClient.setAuthenticator(new OkAuthenticator() { @Override

E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache Error while using Picasso and okhttp in genymotion

依然范特西╮ 提交于 2019-12-18 09:09:05
问题 I'm writing an app which loads a picture from a URL and display in an imageview. here is the code... public class MainActivity extends Activity { private Picasso picasso; private OkHttpClient okHttpClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imageview = (ImageView) findViewById(R.id.imageView); String image_url ="http://www.empireonline.com/images/uploaded/wreck-it-ralph-box-office

What is the reason of this error java.io.IOException: Content-Length and stream length disagree

安稳与你 提交于 2019-12-18 07:38:48
问题 I am getting this error java.io.IOException: Content-Length and stream length disagree on this line of code return response.body().bytes(); this is full code edit: after some google the reason of the error is from okhttp lib if (contentLength != -1L && contentLength != bytes.size.toLong()) { throw IOException( "Content-Length ($contentLength) and stream length (${bytes.size}) disagree") } but how to fix that ? edit: this is full code: public class OkHttpHandler extends AsyncTask<Void, Void,

MultipartBuilder can't be resolved in okhttp:3.0.0-RC1

好久不见. 提交于 2019-12-18 07:34:52
问题 I have used okhttp and It's working fine with following dependency: compile 'com.squareup.okhttp:okhttp:2.3.0' Recently I have updated with: compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1' It shows error like MultipartBuilder can't be resolved. I am uploading image with my Previous Answer of Uploading File. Is there any way to achieve the same thing using okhttp:3.0.0-RC1 ? 回答1: It is called MultipartBody.Builder now. From the ChangeLog: Form and Multipart bodies are now modeled. We've

Android Volley MalformedURLException Bad URL

大憨熊 提交于 2019-12-18 07:28:54
问题 After making a second network request using Volley , I always get this error. It doesn't seem to matter what the url I put in is. Volley always claims it is malformed. 08-04 20:16:26.885 14453-14470/com.thredup.android E/Volley﹕ [994] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL java.lang.RuntimeException: Bad URL at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:127) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java

Consuming One-Shot ResponseBody from Okhttp causes issues with Retrofit

*爱你&永不变心* 提交于 2019-12-18 06:17:30
问题 I am using an Retrofit with an Okhttp interceptor in order to detect if my oauth token has expired. If the token has expired, I want to request a new token, try the request again, then send that response to Retrofit. Here is my interceptor class: public class CustomInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); // try the request Response response = chain.proceed(request); if (response.body().string

How to trust self signed certificate on Android?

无人久伴 提交于 2019-12-18 05:49:09
问题 I have generated self signed certificate for my server. Then added it to Android with Settings -> Security -> Install. When I'm trying to connect to my server with application I'm getting error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. As I understood after I've added certificate to trusted it should work fine with my server or maybe I'm missing something? The idea is to add certificate through Android system and don't change application

Android http connecting with OkHttp Dont work

浪子不回头ぞ 提交于 2019-12-18 04:48:13
问题 I am trying to use OkHttp but it keep crashing. Can someone have a quick look and see if you know whats happening. Thank you. Log cat: 01-24 08:34:46.952: E/AndroidRuntime(31953): FATAL EXCEPTION: OkHttp Dispatcher 01-24 08:34:46.952: E/AndroidRuntime(31953): java.lang.NoClassDefFoundError: okio.Okio 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squareup.okhttp.internal.http.HttpConnection.<init>(HttpConnection.java:87) 01-24 08:34:46.952: E/AndroidRuntime(31953): at com.squareup.okhttp