retrofit

OkHttp enable/disable gzip compression on requests

懵懂的女人 提交于 2021-02-18 20:59:42
问题 I'm using Retrofit to manage my requests and want to make some tests to check de request size using or not using gzip. By default does OkHttp performs gzip compression to requests or it must be implemented with an interceptor? I've added @Headers({ "Accept-Encoding: gzip, deflate", "Content-Encoding: gzip" }) or: @Headers({ "Content-Type: application/json;charset=utf-8", "Accept: application/json" }) to my requests and did not see any change on the request length. 回答1: OkHttp will do

SSLProtocolException with HTTPs on Retrofit2

折月煮酒 提交于 2021-02-18 12:45:09
问题 I am running into an issue on Android 4.4 phones (specifically, Galaxy S4, although I believe it's not the fault of the phone itself). While using Retrofit2.Http I receive the following error while connecting on HTTPS: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x737510d0: Failure in SSL library, usually a protocol error error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741

OkHttp doesn't redirect POST requests when used with retrofit

偶尔善良 提交于 2021-02-18 06:41:28
问题 Using retrofit I want to make POST request to http://milzinas.lt/oauthsilent/authorize . This URL is special because it redirects you to http://milzinas.e-bros.lt/oauthsilent/authorize . My retrofit setup uses OkHttpClient . If I make request using OkHttpClient only then redirecting works fine, i.e. 401 status code is received. However, when I use the same OkHttpClient with retrofit then response is status code 307. I think this has something to do with OkClient implementation which wraps the

Why is RxJava often used with Retrofit?

谁说我不能喝 提交于 2021-02-17 08:36:50
问题 What is the benefit of using Retrofit in combination with Rxjava? 回答1: Question Retrofit Already in run on background thread. Then why need another background task RxJava? I think most importanly, avoid nested callbacks( callback hell ). e.g) Callback hell (Retrofit) public interface MyService { @GET("users") Call<List<UserModel>> getUser(); @GET("userinfo") Call<UserInfoModel> getUserInfoById(@Query("id") Integer id); } service.getUser().enqueue(new Callback<UserModel>() { @Override public

Retrofit 2: No virtual method newJsonReader(Ljava/io/Reader;) NoSuchMethodException

坚强是说给别人听的谎言 提交于 2021-02-16 20:23:41
问题 I am searching for this error whole internet, but yet, only one stackoverflow entry with no answer or comment. I am trying to use Retrofit 2. It is my first time using it. Here are my dependencies: compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.google.code.gson:gson:2.6.2' I exclued any OkHttp libraries as Retrofit already uses it. This is my request interface: public interface LoginService { @POST(HTTPService.AUTHENTICATIO

HTTP FAILED: java.io.IOException: unexpected end of stream exception while making https request

好久不见. 提交于 2021-02-16 20:05:02
问题 We are previously using http apis and now we have migrated to https, with same code we are facing the exception HTTP FAILED: java.io.IOException: unexpected end of stream (this is for some device and for some network calls). We are using the OkHttp and Retrofit from android app. Below is our code @Provides @ApplicationScope OkHttpClient provideOkHttpClientV2( HttpLoggingInterceptor logging, Interceptor headerInterceptor) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); //Removed

HTTP FAILED: java.io.IOException: unexpected end of stream exception while making https request

て烟熏妆下的殇ゞ 提交于 2021-02-16 20:04:23
问题 We are previously using http apis and now we have migrated to https, with same code we are facing the exception HTTP FAILED: java.io.IOException: unexpected end of stream (this is for some device and for some network calls). We are using the OkHttp and Retrofit from android app. Below is our code @Provides @ApplicationScope OkHttpClient provideOkHttpClientV2( HttpLoggingInterceptor logging, Interceptor headerInterceptor) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); //Removed

【Android】基于WanAndroid开放API实现的文章阅读APP

只谈情不闲聊 提交于 2021-02-14 23:56:58
个人博客: http://www.milovetingting.cn 简介 基于 WanAndroid 开放 API 开发的技术文章阅读App。主要功能包括:首页、体系、项目、公众号、搜索、登录、收藏、夜间模式等。 用到的第三方框架 RxJava RxAndroid Retrofit EventBus ButterKnife Gson Glide LitePal AndroidUtilCode SmartRefreshLayout permissionsdispatcher Banner AgentWeb WaveLoadingView FlowLayout 效果图 首页:展示轮播图、推荐文章列表,列表支持下拉刷新、上拉加载。 体系分类:展示体系的一级、二级分类信息,支持下拉刷新。 二级体系分类:展示具体二级分类下的文章列表,支持下拉刷新、上拉加载。 项目:项目列表,支持下拉刷新、上拉加载。 公众号:公众号列表,支持下拉刷新、上拉加载。 搜索: 搜索结果: 文章内容: 菜单栏:包含用户信息、收藏列表、设置 登录前: 登录: 注册: 登录后: 收藏列表: 设置: 夜间模式 APK下载 项目地址: https://github.com/milovetingting/WanAndroid/tree/master/WanAndroid WanAndroid 为非组件化应用。

带你封装自己的MVP+Retrofit+RxJava2框架(一)

守給你的承諾、 提交于 2021-02-11 20:44:22
前言 文本已经收录到我的Github个人博客,欢迎大佬们光临寒舍: 我的GIthub博客 看完本篇文章的,可以看下 带你封装自己的MVP+Retrofit+RxJava2框架(二) ,里面封装得到了改进 本篇文章需要已经具备的知识: MVP 的概念和基本使用 Retrofit 框架的基本使用 RxJava2 框架的基本使用 ButterKnife 框架的基本使用 Base 基类的概念 学习清单: Activity 和 Fragment 基类的封装 MVP 的封装使用 一.为什么要封装这套框架呢? 在搞清楚这个问题之前,我们回顾一下基本概念 RxJava : ReactiveX 在 JVM 上的一个实现, ReactiveX 使用 Observable 序列组合异步和基于事件的程序;掌握了它,你可以优美地处理异步任务和事件的回调 Retrofit :一个 RESTful 的 HTTP 网络请求框架的封装,网络请求的工作本质上是 OkHttp 完成,而 Retrofit 仅负责 网络请求接口的封装:掌握了它,你能优美地进行网络请求。 MVP :一种解耦模型和视图的模式,是现在很多公司的主流模式。 由此可见,在平时的开发中熟练运用这种模式,不仅可以满足生活中大部分应用程序的场景,还可以为将来的工作积攒宝贵的实战经验。 二.核心用法 本项目基于 Android X 进行构建

Kotlin Retrofit Query Annotation parameters

和自甴很熟 提交于 2021-02-10 15:10:22
问题 So I have have this an interface for the NetworkConfig.kt class: interface getProductList { @GET("stock") fun getProducts(@Query("outcode") stkOutcode: String): Call<OutletListPOJODataClasses> } and this is a code snippet from the Activity I use to fetch url: NetworkConfig().getProductListService() .getProducts() //What should i pass here ? .enqueue(object : Callback<ProductListPOJODataClasses> { override fun onFailure(call: Call<ProductListPOJODataClasses>, t: Throwable) { Toast.makeText(