okhttp

Retrofit OkHttp SSLHandshakeException

我只是一个虾纸丫 提交于 2019-12-03 13:51:02
问题 I am using OkHttp as the client in Retrofit. I am unable to hit a certain https url. This server supports TLS 1.0 only and the following ciphers TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_RC4_128_MD5 Here's how I am instantiating my OkHttpClient: OkHttpClient client = new OkHttpClient(); try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { @Override public void checkClientTrusted( java.security

Upload dynamic number of files with okHttp3

柔情痞子 提交于 2019-12-03 12:28:04
问题 How to manage upload of dynamic number of files with OkHttp v3, I have already implemented with older version of OkHttp which was compile 'com.squareup.okhttp:okhttp:2.6.0' There are some changes in class Form and Multipart bodies are now modeled. They've replaced the opaque FormEncodingBuilder with the more powerful FormBody and FormBody.Builder combo. Similarly they've upgraded MultipartBuilder into MultipartBody, MultipartBody.Part, and MultipartBody.Builder. below code is of older version

Got this error with retrofit2 & OkHttp3. Unable to resolve host “<host-name>”: No address associated with hostname

醉酒当歌 提交于 2019-12-03 10:32:16
I am using the retrofit 2 and OkHttp3 to request data from server. I just added a offline cache code but It's not working as expected. I got the error "Unable to resolve host "<>": No address associated with hostname." This occurs when It's try to get the retrieve data from the cache(when no internet connection). A code snippet is below. public static Interceptor provideCacheInterceptor() { return new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); // re-write response header to force use of cache

OkHttp3 Never Timeout on slow internet

对着背影说爱祢 提交于 2019-12-03 10:10:47
问题 First of all, I have read so many questions regarding my question but it never gives me the solution. Here are some of the questions which I read regarding my question. Question 1 Question 2 Qusetion 3 Question 4 Question 5 Question 6 Question 7 I also read this article regarding my question but it also never provide me the solution. Problem: I am using Okhhtp3 library in my application for Web Services. It's working fine but when the internet connection slow or unreliable connection it's

OkHTTPClient pass cookies to Webview

十年热恋 提交于 2019-12-03 10:09:04
问题 I am logging in as a user via an OKHttpClient post and I would like to share the cookies with the webview. 回答1: With OkHttp 3.0, you can use a method similar to sharing with HttpURLConnection by making a WebkitCookieManagerProxy that uses the webkit cookie store. Adapted from Pass cookies from HttpURLConnection (java.net.CookieManager) to WebView (android.webkit.CookieManager) . public class WebkitCookieManagerProxy extends CookieManager implements CookieJar { private android.webkit

Retrofit “IllegalStateException: Already executed”

南笙酒味 提交于 2019-12-03 09:41:59
I have a Retrofit network call that id like to run every 5 seconds. My current code: Handler h = new Handler(); int delay = 5000; //milliseconds h.postDelayed(new Runnable() { public void run() { call.enqueue(new Callback<ApiResponse>() { @Override public void onResponse(Response<ApiResponse> response) { Log.d("api", "response: " + response.body().getPosition().getLatitude().toString()); } @Override public void onFailure(Throwable t) { } }); h.postDelayed(this, delay); } }, delay); This runs once, but then throws the following: java.lang.IllegalStateException: Already executed. at retrofit2

How to make OKHTTP post request without a request body?

浪子不回头ぞ 提交于 2019-12-03 09:33:15
Possible way to make OkHTTP post request without a request body in okhttp library ? Justcurious RequestBody reqbody = RequestBody.create(null, new byte[0]); Request.Builder formBody = new Request.Builder().url(url).method("POST",reqbody).header("Content-Length", "0"); clientOk.newCall(formBody.build()).enqueue(OkHttpCallBack()); This worked for me: RequestBody body = RequestBody.create(null, new byte[]{}); 来源: https://stackoverflow.com/questions/35743516/how-to-make-okhttp-post-request-without-a-request-body

Retrofit SocketTimeOutException in sending multiparty or JSON data in android

╄→尐↘猪︶ㄣ 提交于 2019-12-03 08:15:01
Facing problem in sending a Mutipart or JSON data through retrofit lib Retrofit Interface @Multipart @POST("/api/v1/protected/updateprofile") void uploadPhoto(@Part("name") String name, @Part("image") TypedFile file, Callback<ApiResponseModel> callback); Adapter Code private RestApi restApi; RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(getClient())).setConverter(new GsonConverter(gson)).setRequestInterceptor(interceptor).setLogLevel(RestAdapter.LogLevel.FULL).setEndpoint(Config.baseUrl).build(); restApi = restAdapter.create(RestApi.class); Error Log Generated

InterruptedIOException while using Retrofit2 with rx when retryOn

↘锁芯ラ 提交于 2019-12-03 07:24:19
I'm using retrofit 2 with rx-android I have quite complex retry logic, which partially works . I cut off irrelevant code to simplify it. Here it is: public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>>, Constants { @Override public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts.flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { int statusCode = 500; if (throwable instanceof HttpException) { HttpException httpException = (HttpException) throwable; statusCode =

Glide - adding header to request

你说的曾经没有我的故事 提交于 2019-12-03 06:57:32
问题 is there a method to add custom header to request when image is downloaded? I can use volley or okhttp in Glide. I try add cookie to cookiemanager in okhttpclient, but it doesn't helped. Is there a method to debug request response in Glide? Best regards Tom 回答1: Since 3.6.0 it's possible to set custom headers for each request: GlideUrl glideUrl = new GlideUrl("url", new LazyHeaders.Builder() .addHeader("key1", "value") .addHeader("key2", new LazyHeaderFactory() { @Override public String