Questions tagged [okhttp]

1

votes
1

answer
3.9k

Views

how to solve java.lang.NoClassDefFoundError: okio.Okio?

I have an app that work very well but some times when I add some class and code to my program my app crashes. In my logcat error is for this: 8871-8929/com.example.first E/AndroidRuntime﹕ FATAL EXCEPTION: pool-4-thread-1 java.lang.NoClassDefFoundError: okio.Okio at com.squareup.okhttp.internal.htt...
android
6

votes
0

answer
224

Views

Uploading a JSON array with multiple files

I have the following json that I need to upload: [{"key":"value","key1":"value1"}, [{"innerkey":"innervalue","filename":"name"},{"innerkey":"innervalue","filename":"name"}]] the two innerkeys which are inside the JsonArray have two files which need to be uploaded. I am using okhttp multipart to uplo...
Pemba Tamang
0

votes
0

answer
3

Views

java.net.SocketTimeoutException occurred after 1s~3s but my ok http timeout set 10s

My app is using Retrofit+okhttp. Sometimes, it throw SocketTimeoutException just through 1s~3s after request but my okhttp timeout is setting 10s. It's my code. private static OkHttpClient getClient() { OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .writeTime...
AllenHuang
1

votes
2

answer
393

Views

No HTTP request is send from retrofit /Android/

I'm trying to send data to an API from my Android project using Retrofit. Everything seems to work without errors but no http request leaves the application. I can confirm this with Wireshark screening and API console log. Here is an example pseudo code of this parts of my application: // sample c...
nikitz
1

votes
1

answer
1.3k

Views

Android - how to upload video in chunks using OkHTTP?

please see my below code which I use to upload a video to a server. However, for large enough videos, I'm getting an OutOfMemory exception. InputStream stream = getContentResolver().openInputStream(videoUri); byte[] byteArray = IOUtils.toByteArray(stream); RequestBody requestBody = new MultipartBod...
JK140
1

votes
1

answer
4.6k

Views

Convert JsonArray to byte[] array in android

I have the following jsonarray: { "_id" :"value", "data": "value", "array" : [{ "x" : "value", "y" : "value" }, { "x" : "value", "y" : "value" }] } How to convert this to byte[] array ?
user1002448
1

votes
2

answer
1.8k

Views

OkHttp Connection pool maxIdleConnections per host or global?

When using HttpOk in sync. mode with a connection pool, the maxIdleConnections is a limit per host or global? In the source code I can see a comment saying it is per address but however I can't find this information in a public documentation (javadoc, wiki) and also when looking at the source code i...
eugen
1

votes
1

answer
1.4k

Views

Gradle - Error:Failed to find: com.squareup.okhttp:okhttp:2.4.0

I just try to use OkHttp but I have the following issue when I sync my gradle file with Android Studio : Error:Failed to find: com.squareup.okhttp:okhttp:2.4.0 Here is the dependencies part of my build.gradle file : dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.androi...
Alex R.
1

votes
1

answer
219

Views

Proper behavior for clients receiving status 307

I've been using OkHttp for hitting Nest's Firebase API (I don't like the Firebase SDK since it keeps a socket open, which is power hungry for my purposes). On several of the requests, I'll get a status code 307 to redirect to another URL. This isn't terribly surprising. What is surprising is that Ok...
keyboardr
1

votes
1

answer
664

Views

Picasso and OkHttp

A question about a thing that I don't understand: does Picasso use OkHttp as default downloader, or should I configure it by myself? And - if not - why should I use Picasso with OkHttp? What are the advantages compared to the default Picasso? Thanks. (currently I'm using Picasso v.2.5.2)
1

votes
2

answer
3.7k

Views

Android Volley NoConnectionError: java.io.InterruptedIOException

I have below code to make request to web service using volley: RequestQueue requestQueue = Volley.newRequestQueue(getActivity(),new OkHttpStack()); GsonRequest request = new GsonRequest(Method.POST,Config.MYPOSTLINK, myData.class, getSuccessListener, getErrorListener); request.setParams("Token", to...
Jemshit Iskenderov
1

votes
1

answer
419

Views

OKHttp connection failed when I use sync

I got and SSLHandshakeException when I use synchronized connection to an HTTPS server. If I use asynchronized connection to same url I can't get two differentes answer: Case 1: If I call the asynchronized request directly from main thread I got an 403 forbidden and empty response body. Case 2: If...
lagos
1

votes
3

answer
106

Views

async method is not running when clicking on button

There is a button in my app and when I click on it , it declares the method insertintodatabase. But, nothing is happening when I am clicking on it , even the log is not showing anything. Where is the problem ? Please suggest. private final OkHttpClient client = new OkHttpClient(); public void SignUp...
Moudiz
1

votes
2

answer
1.3k

Views

send data using okhttp without async task

Can I use this way to upload string to server using Okhttp ? protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.register); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeA...
Moudiz
1

votes
2

answer
3.7k

Views

Retrofit+OkHttp+Picasso okio dependency

Okay, so I am using Retrofit, OkHttp and Picasso in my project. Here are my relevant dependencies in the project: compile ('com.squareup.retrofit:retrofit:2.0.0-beta2') compile ('com.squareup.retrofit:converter-gson:2.0.0-beta2') compile ('com.squareup.okhttp:okhttp-urlconnection:2.5.0') compile ('...
Anonomousxxx
1

votes
1

answer
3.5k

Views

Adding auth token as header to okhttp

I have the method below for making GET calls. I need to add a header to it, so as to pass the userToken to the server through the header. How do I do that? public static String getJsonStringFromHttpGet(String url) { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .u...
Nouvel Travay
1

votes
2

answer
1.6k

Views

How to download multiple files with OkHttp?

I need to download multiple files with OkHttp libarary. And after all downloads are finished I need to inform user. I know how to download one file with OkHttp. Here is code: OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url) .build(); okHttpClient.newC...
Zookey
0

votes
1

answer
74

Views

Use a certificate in an okhttp request with android

The server of the application in which I work uses a certificate to allow requests. I have it installed, for example, in the desktop Chrome browser and it works fine. It´s a usual certificate with the extension .cer Now I have to make this certificate work also in my android application and, honest...
Sergio76
1

votes
1

answer
2.3k

Views

Fail to run app using OkHttp on 'Android L' emulator

Our app uses latest version of OkHttp (2.0.0) + Okio (1.0.0) + Picasso (2.3.2) and I wanted to try it out on the new "Android L" emulator (Intel) and it gets installed but when loading the app i get this: 06-27 09:47:16.214: E/AndroidRuntime(2815): FATAL EXCEPTION: main 06-27 09:47:16.214: E/Android...
1

votes
1

answer
344

Views

Is there a 'ResponseInterceptor' (as its counterpart RequestInterceptor) component for Retrofit?

I'm using Retrofit and most of its components like ErrorHandler, Callbacks and RequestInterceptor, etc. But I miss something like a 'ResponseInterceptor', something that would allow me to filter or read headers that came on the response in generic way, as a central point, instead of having to set a...
Alécio Carvalho
1

votes
2

answer
1k

Views

Error Parse 1.9.3 and OkHTTP 2.0.0

When I use version 1.9.3 of Parse (Parse-1.9.3.jar) and OkHTTP version 2.0.0 in the same project, I get this error: java.lang.NoSuchMethodError: No virtual method setFollowRedirects(Z)V in class Lcom/squareup/okhttp/OkHttpClient; or its super classes (declaration of 'com.squareup.okhttp.OkHttpClient...
Sérgio Moura
1

votes
1

answer
591

Views

Android Wear + Webservice Calls

I am trying to use OkHttp with Android Wear App. All the Internet and required permissions are there. As of goggling, I found that we can't communicate Web-service directly from the App ? We'll have to use Message and Data Api to pass the Data from Device to wear ? Any other way for Webservice calli...
Vishal Khakhkhar
6

votes
1

answer
11.7k

Views

How to trust self signed certificate on Android?

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 unders...
Forest
2

votes
3

answer
2k

Views

Issues with Caching on OkHttpClient 2.0

I have an issue with caching using OkHttpClient 2.0. It seems that the Response is ignoring the Cache-Control header completely. This is how I am setting up the client and the cache. OkHttpClient client = new OkHttpClient(); cache = new Cache(new File(Session.getInstance().getContext().getCacheDir()...
Ashish
16

votes
5

answer
17.8k

Views

RETROFIT & AUTH COOKIE

I need to know how to add an authorization cookie header in retrofit. I have seen advice like using request intercepter etc. Below is what I am trying, but is this correct? First of all I already needed a RequestAdatper to get the session id the first time around. This can only be set by the build...
user3186731
2

votes
1

answer
1.7k

Views

OkHttp and UTF-8 character encoding

I have a question about OkHttp in Android and its support for character encoding, specifically using UTF-8 to support swedish characters å, ä and ö (and capitals ÅÄÖ). The app we are building uses OkHttp to make GET and POST calls to our server system. The server runs on Tomcat behind Apache....
Mats Andersson
17

votes
1

answer
10.5k

Views

Why should I use OkHttp instead of android httpClient and AsyncTask

In the presentation of Paresh Mayani at SpeakerDeck (https://speakerdeck.com/pareshmayani/lazy-android-developers-be-productive) he says that it's better to use OkHttp or Retrofit instead of AsyncTask with DefaultHttpClient. My question is why? Why are they faster? Aren't those also libraries based...
RCB
17

votes
5

answer
13.4k

Views

HTTP Caching with Retrofit 2.0.x

I'm trying to cache some responses in my app using Retrofit 2.0, but I'm missing something. I installed a caching file as follows: private static File httpCacheDir; private static Cache cache; try { httpCacheDir = new File(getApplicationContext().getCacheDir(), "http"); httpCacheDir.setReadable(true...
Amr Barakat
17

votes
7

answer
3.4k

Views

Retrofit 2.0-beta-2 is adding literal quotes to MultiPart values

Went to upgrade to Retrofit 2.0 and running into this weird problem. I have a method to log a user in public interface ApiInterface { @Multipart @POST("user/login/") Call userLogin(@Part("username") String username, @Part("password") String password); } When I look at the key value POST params on th...
Brian
17

votes
3

answer
18.6k

Views

How to use Retrofit and SimpleXML together in downloading and parsing an XML file from a site?

I just started working with Retrofit. I am working on a project that uses SimpleXML. Can somebody provide me an example in which one fetches an XML from a site e.g. http://www.w3schools.com/xml/simple.xml" and reads it out?
greenspand
4

votes
3

answer
324

Views

Determine transfer rate of upload

I am working on an app which uploads a large amount of data. I want to determine the transfer rate of the upload, to show in a notification. One post suggests using the WifiInfo which will not work for mobile data. Another post suggests getting the network type to estimate the speed. I'm not sat...
Pemba Tamang
18

votes
4

answer
14.2k

Views

Android Volley MalformedURLException Bad URL

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.RuntimeE...
Eric Cochran
18

votes
2

answer
11.7k

Views

Retrofit2: Modifying request body in OkHttp Interceptor

I am using Retrofit 2 (2.0.0-beta3) with OkHttp client in Android application and so far everything going great. But currently I am facing issue with OkHttp Interceptor. The server I am communicating with is taking access token in body of request, so when I intercept the request to add auth token or...
Lala Rukh
18

votes
4

answer
11.6k

Views

Using RxJava and Okhttp

I want to request to a url using okhttp in another thread (like IO thread) and get Response in the Android main thread, But I don't know how to create an Observable.
Santos Black
18

votes
2

answer
8.9k

Views

How to make OKHTTP post request without a request body?

Possible way to make OkHTTP post request without a request body in okhttp library ?
Justcurious
2

votes
1

answer
707

Views

Android, get data from web and update UI (Multi-threading and MVC design pattern)

Currently developing a weather application . I wanna strictly observe 2 rules: MVC Design pattern Multithreading when I deals with network. The problem is combining these things into a whole, here are parts of my code: Weather Class (represent a Weather object) : public class Weather { private int...
Vitaly Sulimov
19

votes
2

answer
1.8k

Views

Image adapter leaking memory

I have a simple ListActivity that shows images and I inizialize my OkHttpClient for Picasso Builder in the constructor of the ImageAdapter class: picassoClient = new OkHttpClient(); picassoClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOExcepti...
GPack
5

votes
2

answer
1.7k

Views

Consuming One-Shot ResponseBody from Okhttp causes issues with Retrofit

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...
tylerjroach
2

votes
1

answer
536

Views

Is there a way to feed a cached response to Retrofit?

For various reasons (one of which being that I have no control on the REST server) I cannot use the standard HTTP cache with OkHTTP. The idea would be to use Retrofit to work with the services and store the responses in a local cache (SQLite). The problem then is how to feed a cached response to R...
5

votes
2

answer
1.7k

Views

OkHttpClient “open” method missing in v2.0

If you are upgrading from OkHttp library from 1.x to 2.x, glaringly the OkHttpClient method "open" is missing. The below code will NOT compile. OkHttpClient client = new OkHttpClient(); HttpURLConnection conn = client.open(url);
sivag1

View additional questions