okhttp

Using OkHttp client via OKClient on Google App Engine throws a “java.lang.NoClassDefFoundError: java.net.ProxySelector” is a restricted class error

自古美人都是妖i 提交于 2019-12-05 01:26:58
I am trying to use OKHTTP (version 2.4.0) along retrofit (1.9.0) on google app engine (1.9.22). Here is the how i use it: OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(COMPOSER_MODULE_CONNECTION_TIMEOUT, TimeUnit.SECONDS); okHttpClient.setReadTimeout(COMPOSER_MODULE_SOCKET_TIMEOUT, TimeUnit.SECONDS); RestAdapter restAdapter = new RestAdapter.Builder() .setLogLevel(RestAdapter.LogLevel.FULL) .setConverter(new JacksonConverter()) .setEndpoint(ENDPOINT_PATH) .setClient(new OkClient(okHttpClient)) .build(); This throws the following error: java.lang

HTTP/2 protocol not working with okhttp

走远了吗. 提交于 2019-12-04 23:35:05
I am using Retrofit 1.9 with okhttp 2.4.0. So far we have SPDY protocol disabled on server side (I checked it by this ). And enabled protocol on server side is HTTP/2 (I checked it by this ). So I was thinking that okhttp will try to make an api call using HTTP/2 (latest one protocol) but it's using HTTP/1.1 on android device 4.2.2 samsung S4 - D/Retrofit : OkHttp-Selected-Protocol: http/1.1 Someone told me that android device doesn't support SPDY until 5.0 (I don't have any proof), so that device never attempted to use a SPDY connection. But I am sure that our server not using SPDY at all I

CLEARTEXT communication to xxx not permitted by network security policy

拜拜、爱过 提交于 2019-12-04 22:49:07
Android P http网络请求不通,报出异常:java.net.UnknownServiceException: CLEARTEXT communication to xxxx not permitted by network security policy Google表示,为保证用户数据和设备的安全,针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的连接,因此运行 Android P 系统的安卓设备无论是接收或者发送流量,未来都不能明码传输,需要使用下一代(Transport Layer Security)传输层安全协议,而 Android Nougat 和 Oreo 则不受影响。 因此在Android P 使用HttpUrlConnection进行http请求会出现以下异常 java.io.IOException: Cleartext HTTP traffic to **** not permitted 使用OKHttp请求则出现 java.net.UnknownServiceException: CLEARTEXT communication ** not permitted by network security policy 在Android P系统的设备上

Downloading files using OkHttp, Okio and RxJava

杀马特。学长 韩版系。学妹 提交于 2019-12-04 21:57:09
I'm trying to download files using OkHttp and writing to disk with Okio. Also I've created an rx observable for this process. It is working, however it is noticeably slower than what I had previously used (Koush's Ion library). Here's how I create the observable: public Observable<FilesWrapper> download(List<Thing> things) { return Observable.from(things) .map(thing -> { File file = new File(getExternalCacheDir() + File.separator + thing.getName()); if (!file.exists()) { Request request = new Request.Builder().url(thing.getUrl()).build(); Response response; try { response = client.newCall

okhttp client throwing exception under TMG proxy server

天大地大妈咪最大 提交于 2019-12-04 20:48:40
I'm using github's square OKHTTP client library for my java application as follows : import java.io.IOException; import java.net.InetSocketAddress; import java.net.Proxy; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import com.squareup.okhttp.Authenticator; import com.squareup.okhttp.Credentials; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request;

OKHttp Authenticator custom http code other than 401 and 407

大憨熊 提交于 2019-12-04 19:08:17
I have oauth token implemented on server side but upon Invalid token or Token expirey i am getting 200 http status code but in response body i have {"code":"4XX", "data":{"some":"object"} When i try to read string in interceptor i get okhttp dispatcher java.lang.illegalstateexception closed because response.body().string() must be called only once. Also i read from here Refreshing OAuth token using Retrofit without modifying all calls that we can use OkHttp Authenticator class but it works only with 401/407 i havent triedn as i will not get this. Is there any way we can customize Authenticator

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

我的未来我决定 提交于 2019-12-04 16:32:10
问题 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 {

Retrofit “IllegalStateException: Already executed”

痴心易碎 提交于 2019-12-04 15:37:26
问题 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

How to make OKHTTP post request without a request body?

梦想与她 提交于 2019-12-04 15:18:43
问题 Possible way to make OkHTTP post request without a request body in okhttp library ? 回答1: 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()); 回答2: This worked for me: RequestBody body = RequestBody.create(null, new byte[]{}); 回答3: "".toRequestBody() "".toRequestBody("application/json".toMediaTypeOrNull()) ..

Android网络编程详解

孤街醉人 提交于 2019-12-04 15:14:40
一、网络的基本概念及Http协议 IP地址和端口号 IP地址:网络中的媚态计算机都必须一个唯一的IP地址作为标识,用一组由“.”分隔的十进制数组成 端口号:IP地址只能保证键数据送到指定的计算机,但无法知道交给该主机的哪个网络程序,因此采用端口号标识计算机上正在运行的进程 每个被发送的网略数据包都包含端口号,用于将该数据帧交给具有相同端口号的应用程序处理 Java的网络编程由Java.net包中的类进行处理 InetAddress类:描述IP地址 HTTP协议 属于应用层的面向对象的协议,适用于分布式超媒体信息系统 主要特点 1、支持C/S模式 2、简单快速:只需传送请求方法和路径,请求方法常用的有:GET、HEAD、POST等 3、灵活:允许传输任意类型的数据对象,用Content-Type进行标记 4、无连接:限制每次连接只处理一个请求 5、无状态:对事务处理没有记忆功能 HTTP的URL的格式: 1、 http://host [:port][/path] 2、http表示要通过HTTP协议来定位网络资源;host表示合法的Internet主机域名或者IP地址;port指定一个端口号,为空则使用默认端口80;path指定请求资源的URI HTTP请求报文 由请求行、请求报头、空行和请求数据4个部分组成 HTTP相应报文 由状态行、消息报头、空行、相应正文组成 常见的状态码