okhttp

Volley + OkHttp on Android gives error on status 200 response

跟風遠走 提交于 2019-12-05 08:39:46
When I make my request with only Volley everything goes well and my StringRequest goes to onResponse. But when I switch to Volley + Okhttp combination, my request goes through, I receive the same response as before but then I get the following error message: E/Volley﹕ [122319] BasicNetwork.performRequest: Unexpected response code 200 for <my request url> java.io.IOException: closed com.android.volley.NetworkError: java.io.IOException: closed at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:182) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)

Picasso not loading pictures in ImageView

这一生的挚爱 提交于 2019-12-05 07:20:45
问题 I'm trying to use Picasso in order to make a lazy picture loading in a ListView. But it's actually not working. In my custom adapter, I get the ImageView, initialize a Picasso object and indicate to load the image into the specified ImageView. To retrieve picture from server, I needed to provide a basic authentication, so I've created a custom interceptor which adds the authentication header. Moreover, I need to trust every SSL certificate because for the moment the certificate is not signed.

OkHttp support for SDK versions less than 21

亡梦爱人 提交于 2019-12-05 06:23:48
OkHttp has recently dropped support for Android 4 , except via a separate 3.12.x branch that will be supported until end of Dec 2020 (and probably receive no more than critical updates or bugfixes). On the assumption that you wish to continue to support Android 4, like I do, since 10% of the Android user base is still a significant proportion, and don't want to be stuck in a dead-end branch... Rather than being stuck on the 3.12.x branch for all sdk versions, is there any way of using the 3.12 branch for sdk < 21 and the 3.13 branch for sdk >= 21 , a bit like it would of course be possible to

OkHttp MockWebServer fails to accept connections when restarted

耗尽温柔 提交于 2019-12-05 05:59:37
I'm using the OkHttp MockWebServer to mock my server responses for unit tests. It works great for the first test, but on the 2nd test my client fails with: Failed to connect to localhost/0:0:0:0:0:0:0:1:63631 This happens even if the 2nd test is exactly the same as the 1st one. Here's what I'm doing: @RunWith(RobolectricTestRunner.class) @Config(shadows = MyClassTest.MyNetworkSecurityPolicy.class, manifest = "src/main/AndroidManifest.xml", constants = BuildConfig.class, sdk = 16) public class MyClassTest { private MockWebServer mockServer; private MyServerApi serverApi; @Before public void

Cache POST requests with OkHttp

落爺英雄遲暮 提交于 2019-12-05 05:57:47
I make some POST requests to my server with OkHttp. This works fine. Now I want use the cache of OkHttp to cache the responses of the requests and use them when the device is offline. I tried many solutions from other questions, but none of them work. I use OkHttp 2.5.0 With the code below, I get a valid response, when the device has internet access. But if I turn the internet off, it throws a java.net. UnknownHostException : Unable to resolve host "example.com": No address associated with hostname Here is my current code, which does not work: Interceptor for rewriting the cache headers:

Retrofit + OkHttp + GZIP-ed JSON

戏子无情 提交于 2019-12-05 05:18:25
I'm new to Retrofit but it seems really powerful. Everything works fine with a normal JSON, but as soon as I try a GZIPed one I just get an error: I/System.out(14883): ------retrofit.RetrofitError: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 Obviously the the gibberish symbols I see in the Log cannot be parsed as JSON. I thought okHttp is catchig that gzip stuff correctly? What am I missing? These jars are in my libs folder: retrofit-1.6.1.jar okhttp-2.0.0.jar gson-2.2.4

org.openqa.selenium.remote.internal.ApacheHttpClient is deprecated in Selenium 3.14.0 - What should be used instead?

匆匆过客 提交于 2019-12-05 03:38:16
I am currently using Selenium 3.14.0 library in which org.openqa.selenium.remote.internal.ApacheHttpClient is deprecated with no other information. Which should be used instead? The class is already removed in the next version, 3.141.59. I am using it with EdgeDriver Service like following: final int connectionTimeout = 2 * 60 * 1000; final int socketTimeout = 10 * 60 * 1000; // 10 minute timeout final ApacheHttpClient.Factory clientFactory = new ApacheHttpClient.Factory( new HttpClientFactory(connectionTimeout, socketTimeout)); ... edgeDriverService = new EdgeDriverService.Builder()

Okhttp Authenticator multithreading

梦想的初衷 提交于 2019-12-05 03:35:29
I am using OkHttp in my android application with several async requests. All requests require a token to be sent with the header. Sometimes I need to refresh the token using a RefreshToken, so I decided to use OkHttp 's Authenticator class. What will happen when 2 or more async requests get a 401 response code from the server at the same time? Would the Authenticator's authenticate() method be called for each request, or it will only called once for the first request that got a 401? @Override public Request authenticate(Proxy proxy, Response response) throws IOException { return null; } How to

how to get response body in okhttp when code is 401

拜拜、爱过 提交于 2019-12-05 02:45:20
i am using okHttp 3.2.0 and here is code for building request object MediaType JSON = MediaType.parse(AppConstants.CONTENT_TYPE_VALUE_JSON); RequestBody body = RequestBody.create(JSON, requestBody); HttpUrl url = new HttpUrl.Builder() .scheme("http") .host("192.168.0.104") .port(8080) .addPathSegment("mutterfly-server") .addPathSegment("j_spring_security_check") .addQueryParameter("j_username", jsonObject.getString("emailId")) .addQueryParameter("j_password", jsonObject.getString("password")) .build(); request = new Request.Builder() .addHeader(AppConstants.CONTENT_TYPE_LABEL, AppConstants

How to cancel the request using OKHTTP

馋奶兔 提交于 2019-12-05 01:38:32
I need to be able to MANAGER some requests with OKHTTP , using the Google Places AutoComplete to receive some predictions by typing the Address. The Problem is Each time that I insert a CHAR it will make a new request but at the same time I need to cancel the previous one! Ex : New York City = 13 Requests at the same time! So I'm using a single instance of Call trying to cancel anything that has been requested but with no success. This is what I did! Address.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if