okhttp

Getting an error Using 'body(): ResponseBody?' is an error. moved to val with okhttp

久未见 提交于 2020-06-13 19:24:07
问题 Using response.body() gives me an error of "Using 'body(): ResponseBody?' is an error. moved to val" i tried removing ? but nothing works the error is in body() override fun onResponse(call: Call, response: Response) { val body = response.body()?.string(); println(body) println("Sucees") 回答1: It looks like you're using OkHttp 4.0.0. The response.body() function has been deprecated. Instead, you need to access the body as a val, like this: override fun onResponse(call: Call, response: Response

TLSv1 is not enabled or not supported by the client

柔情痞子 提交于 2020-05-31 06:17:38
问题 i use okhttp to send request to server but i got the error Server chose TLSv1, but that protocol version is not enabled or not supported by the client. javax.net.ssl.SSLHandshakeException: Server chose TLSv1, but that protocol version is not enabled or not supported by the client. at sun.security.ssl.ClientHandshaker.serverHello(ClientHandshaker.java:452) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:206) at sun.security.ssl.Handshaker.processLoop(Handshaker.java

How to fix my errors at okHttp3 webscocket android?

萝らか妹 提交于 2020-05-17 07:06:09
问题 I receive such error at my websocket: Error: [okio.RealBufferedSource.require(RealBufferedSource.kt:201), okio.RealBufferedSource.readByte(RealBufferedSource.kt:210), okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.kt:119), okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:102), okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293), okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195), okhttp3.internal.connection

How to fix my errors at okHttp3 webscocket android?

我怕爱的太早我们不能终老 提交于 2020-05-17 07:05:24
问题 I receive such error at my websocket: Error: [okio.RealBufferedSource.require(RealBufferedSource.kt:201), okio.RealBufferedSource.readByte(RealBufferedSource.kt:210), okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.kt:119), okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:102), okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293), okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195), okhttp3.internal.connection

Retrofit POST java.io.IOException: unexpected end of stream on Connection caused by java.io.EOFException: \n not found:

穿精又带淫゛_ 提交于 2020-05-15 08:04:54
问题 I have went through all the question related to this and yet, I haven't found a solution that works for me. Im using retrofit 2.8.1 and OkHttp 4.5.0 . My service interface looks like the following public interface MlApiService { @POST @Multipart Call<List<PreprocessedDocument>> postDocument( @Url String apiUrl, @Part MultipartBody.Part document, @Part ( "document_id") RequestBody documentId ); } And I build the client like the following with requestTimeoutInSeconds set to 90 seconds. public

OKhttp PUT example

强颜欢笑 提交于 2020-05-11 04:08:48
问题 My requirement is to use PUT , send a header and a body to server which will update something in the database. I just read okHttp documentation and I was trying to use their POST example but it doesn't work for my use case (I think it might be because the server requires me to use PUT instead of POST ) . This is my method with POST : public void postRequestWithHeaderAndBody(String url, String header, String jsonBody) { MediaType JSON = MediaType.parse("application/json; charset=utf-8");

OKhttp PUT example

孤街醉人 提交于 2020-05-11 04:07:16
问题 My requirement is to use PUT , send a header and a body to server which will update something in the database. I just read okHttp documentation and I was trying to use their POST example but it doesn't work for my use case (I think it might be because the server requires me to use PUT instead of POST ) . This is my method with POST : public void postRequestWithHeaderAndBody(String url, String header, String jsonBody) { MediaType JSON = MediaType.parse("application/json; charset=utf-8");

http请求工具-OkHttp用法

十年热恋 提交于 2020-05-05 18:03:45
OKHttp介绍 okhttp是一个第三方类库,用于android中请求网络。这是一个开源项目,是安卓端最火热的轻量级框架,由移动支付Square公司贡献(该公司还贡献了Picasso和LeakCanary) 。用于替代HttpUrlConnection和Apache HttpClient(android API23 里已移除HttpClient)。 okhttp有自己的官网,官网网址: OKHttp官网 如果想了解原码可以在github上下载,地址是: https://github.com/square/okhttp 在AndroidStudio中使用不需要下载jar包,直接添加依赖即可: compile ‘com.squareup.okhttp3:okhttp:3.4.1’ 在开发中我们会经常需要用到http请求,这里简单介绍一个http请求工具okHttp的用法 1、导入jar包 1 <dependency> 2 <groupId>com.squareup.okhttp3</groupId> 3 <artifactId>okhttp</artifactId> 4 <version>3.9.1</version> 5 </dependency> 2、为了便于以后使用,这里封装一个OkHttpUtil的工具类 get请求 1 /** 2 * get请求 3 * @param

Android开发 retrofit入门讲解

我怕爱的太早我们不能终老 提交于 2020-05-05 18:02:18
前言    retrofit基于okhttp封装的网络请求框架,网络请求的工作本质上是 OkHttp 完成,而 retrofit 仅负责网络请求接口的封装.如果你不了解OKhttp建议你还是先了解它在来学习使用retrofit,传送门: Android 开发 框架系列 OkHttp使用详解   Retrofit优势,就是简洁易用,解耦,扩展性强,可搭配多种Json解析框架(例如Gson),另外还支持RxJava. 但是,这篇博客不讲解RxJava配合使用的部分,与RxJava的配合使用将在另外一篇博客中讲解.   另外 retrofit 已经是封装的非常好了,已经最大程度上的匹配各种使用情况,所以不建议多此一举的再次 封装 retrofit(最多封装 retrofit 的单例) . 再次封装不会看起来很帅也不会让你很牛逼. 只会让你看起来更蠢.把已经很拓展很解耦的实现全部破坏. Github地址    https://github.com/square/retrofit 依赖    如果你不需要使用RxJava模式,那么你只需要依赖下面2个: implementation ' com.squareup.retrofit2:retrofit:2.6.2 ' implementation ' com.squareup.retrofit2:converter-gson:2.4.0 '  

Android 网络请求Retrofit + RxJava

。_饼干妹妹 提交于 2020-05-05 18:01:59
一、背景 经常看到项目用Retrofit+RxJava+RxAndroid的框架,为了看懂项目的结构。现在来了解一下,Retrofit: Retrofit是Square 公司开发的一款正对Android 网络请求的框架。底层基于OkHttp 实现,OkHttp 已经得到了google 官方的认可OkHttp: 也是Square 开源的网络请求库 RxJava:RxJava 在 GitHub 主页上的自我介绍是 “a library for composing asynchronous and event-based programs using observable sequences for the Java VM”(一个在 Java VM 上使用可观测的序列来组成异步的、基于事件的程序的库)。这就是 RxJava ,概括得非常精准。总之就是让异步操作变得非常简单。 各自的职责:Retrofit 负责请求的数据和请求的结果,使用接口的方式呈现,OkHttp 负责请求的过程,RxJava 负责异步,各种线程之间的切换RxJava + Retrofit + okHttp 已成为当前Android 网络请求最流行的方式。 二、Retrofit 写一个网络请求 1,首先,要使用Retrofit ,你肯定需要把它的包引入,在你的build.gradle文件中添加如下配置: compile