okhttp3

OkHTTPClient Proxy authentication how to?

我与影子孤独终老i 提交于 2019-11-27 12:13:17
Question: How do I add a authorization proxy to OkHTTP. I know that OkHTTP's builder does support proxies although I am having a hard time setting one up. /** * Given a Url and a base64 encoded password return the contents of a website. * @param urlString * @param password * @return JSON */ public String getURLJson(String urlString, String password) { OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .writeTimeout(60, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) .build(); Request request = new Request.Builder() .url(urlString) .get() .addHeader(

How to add list of Object (i.e UserData) type to MultipartBody in OkHttpClient

◇◆丶佛笑我妖孽 提交于 2019-11-27 08:44:04
问题 I have an ArrayList of Object that I need to put into my MultipartBody.Builder.I have tried using different methods of .addFormDataPart but not working. This is how I'm putting it into the request. Any help would be appreciated. Thanks My JSON on the server is formatted like this { "formData": [ { "name": "string", "value": { any-object(string,file,long....etc) } } ], "tripId": "string" } This is how I am doing it private RequestBody getMultipartData(Object postData) { MultipartBody.Builder

Okhttp android Websocket and Jetty Server connection with SSL

為{幸葍}努か 提交于 2019-11-27 08:34:15
问题 I have my okhttpclient android websocket and jetty stand-alone server given below. I have to enable strong security for the communication between the android client and jetty server. I am facing issue on client side which is given below. Server Side package com.wss.okhttp; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java

java.lang.NoClassDefFoundError: okhttp3.internal.Util

旧时模样 提交于 2019-11-27 07:26:26
问题 [enter image description here][1] My program can run Android 5.1 phone , but the phone will not be able to run Android 4.3 , and will run out of the bottom of the error > E/AndroidRuntime: FATAL EXCEPTION: EventThread >java.lang.NoClassDefFoundError: okhttp3.internal.Util >at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:65) >at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.java:381)> at>io.socket.engineio.client.transports.WebSocket.doOpen(WebSocket.java:51) >at io.socket.engineio

React Native & okhttp on Android - Set User-Agent

 ̄綄美尐妖づ 提交于 2019-11-27 06:03:04
问题 I'm trying to set the User-Agent with React Native on Android. Did some research and it looks like I should use an okhttp Interceptor . An example that I've found explains how this should be done(Link) but then I am not sure on how to register the Interceptor. So in order to set the User-Agent I am using this class: public class CustomInterceptor implements Interceptor { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request originalRequest = chain.request()

java.lang.NoClassDefFoundError: okhttp3.OkHttpClient$Builder

回眸只為那壹抹淺笑 提交于 2019-11-27 03:33:00
问题 In my project, I have used OkHttp(version 2.5.0) as my network request library. But few days ago, I tried Retrofit2 as part of my app's network request library, as you know, the new Retrofit2 library dependence on OkHttp(version 3.2.0).So here comes the problem that when my app runs on android phone whose android version under android 5.0 always causes crash(larger version works well and causes no crash), the crash stack information shows as below: 04-15 21:28:51.185 17238-17238/com.comingx

OKHTTP 3 Tracking Multipart upload progress

寵の児 提交于 2019-11-27 02:43:32
问题 How can I track progress of upload in OkHttp 3 I can find answers for v2 but not v3, like this A sample Multipart request from OkHttp recipes private static final String IMGUR_CLIENT_ID = "..."; private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png"); private final OkHttpClient client = new OkHttpClient(); public void run() throws Exception { // Use the imgur image upload API as documented at https://api.imgur.com/endpoints/image RequestBody requestBody = new

Websocket paused when android app goes to background

混江龙づ霸主 提交于 2019-11-26 23:37:58
问题 My android app starts a service that opens a websocket to communicate to a remote server. The service spawns a thread whose run method looks like this. public void run() { try { super.run(); for(int i = 1; i < 1000; i++) { Log.d(TAG, String.format(" *** Iteration #%d.", i)); Thread.sleep(3000); // Dummy load. mWebsocket.sendTextMessage("Test"); } } catch (Exception exc) { Log.d(MY_TAG, "MyThread.run - Exception: " + exc.getMessage()); } } When I turn off the screen or send the app to the

Image upload using okHttp

限于喜欢 提交于 2019-11-26 22:52:49
i want to upload image using okhttp but i am not able to find MultipartBuilder for Post Image.What can i use instead of this. Here is my code public static JSONObject uploadImage(File file) { try { final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png"); RequestBody req = new MultipartBuilder().setType(MultipartBody.FORM).addFormDataPart("userid", "8457851245") .addFormDataPart("userfile","profile.png", RequestBody.create(MEDIA_TYPE_PNG, file)).build(); Request request = new Request.Builder() .url("url") .post(req) .build(); OkHttpClient client = new OkHttpClient(); Response response =

ProtocolException: Expected ':status' header not present

做~自己de王妃 提交于 2019-11-26 20:40:05
问题 Retrofit network calls fails with a Protocol Exception suddenly in a working app. The app was working till yesterday and today all the network calls fails. The calls works fine with HTTP but fails with HTTPS. Here is the logs, java.net.ProtocolException: Expected ':status' header not present 10-18 14:59:01.103 30746-30746/? W/System.err: at okhttp3.internal.http.Http2xStream.readHttp2HeadersList(Http2xStream.java:262) 10-18 14:59:01.103 30746-30746/? W/System.err: at okhttp3.internal.http