okhttp

What is the difference between the OkHttp methods .toString() and .string()?

狂风中的少年 提交于 2019-12-20 01:34:15
问题 I have a snippet of code: override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { try { Log.d("DEBUG POST=====>", response.body()!!.string()) }catch(e:IOException) { e.printStackTrace() } } When I use response.body()!!.string() I get the correct output, and JSON body. When I use: response.body().toString() I get okhttp3.ResponseBody$1@c626d25 Can anyone kindly tell me what is the difference between the two methods? 回答1: string() isn't a valid Kotlin (or Java)

Program type already present: com.squareup.okhttp.Address

不想你离开。 提交于 2019-12-19 23:21:18
问题 I am trying to configure my android app to use Firebase Cloud Firestore. I also have dependencies on OKHttp3. Gradle will sync fine but I am unable to compile the app and run it. And I get the following error: Program type already present: com.squareup.okhttp.Address I have followed all the steps described here: https://firebase.google.com/docs/firestore/quickstart and I can run the app fine until I add this line to my build.gradle file: implementation 'com.google.firebase:firebase-database

OkHttpClient limit number of connections?

﹥>﹥吖頭↗ 提交于 2019-12-19 14:23:11
问题 Is it possible with OkHttpClient to limit the number of live connections? So if limit reached, no new connection is picked and established? My app starts many connection at same time. 回答1: The number of connections is configurable in the Dispatcher, not in the ConnectionPool that only allows to configure the max idle connections and the keep alive functionality. The dispatcher allows to configure the number of connections by hosts and the max number of connections, defaults are 5 per hosts

App crash on HttpLoggingInterceptor

喜夏-厌秋 提交于 2019-12-19 06:53:36
问题 I've created project with Retrofit 2, okhttp and okhttp:logging-interceptor. private static APIInterface apiInterface; private static RestClient restClient; private static HttpLoggingInterceptor interceptor; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); okHttpClient.setReadTimeout(30, TimeUnit.SECONDS); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request

App crash on HttpLoggingInterceptor

孤街浪徒 提交于 2019-12-19 06:51:38
问题 I've created project with Retrofit 2, okhttp and okhttp:logging-interceptor. private static APIInterface apiInterface; private static RestClient restClient; private static HttpLoggingInterceptor interceptor; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); okHttpClient.setReadTimeout(30, TimeUnit.SECONDS); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request

Java - Retrieving Result from OkHttp Asynchronous GET

倾然丶 夕夏残阳落幕 提交于 2019-12-19 04:57:15
问题 So I have a web-app in Spring Boot, and there is a part where I make many HTTP requests to an API, and it seems to timeout if too many requests are made. I heard that switching from Synchronous to Asynchronous requests might help this issue. Using OkHttp, this is what my Synchronous GET request looks like: private JSONObject run(String url) throws Exception { Request newRequest = new Request.Builder() .url(url) .addHeader("Authorization", token) .build(); try (Response response = client

How to suppress Charset being automatically added to Content-Type in okhttp

橙三吉。 提交于 2019-12-18 19:01:02
问题 Consider the following code: OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("text/plain; charset=utf-8"); // [A] RequestBody body = RequestBody.create(mediaType, media); String[] aclHeader = "x-goog-acl:public-read".split(":"); Request request = new Request.Builder() .addHeader("Content-Type", "text/plain") // [B] .addHeader(aclHeader[0], aclHeader[1]) .url(url) .put(body) .build(); Response response = client.newCall(request).execute(); I am accessing GCS from

How to handle auth0 403 error without adding specific code everywhere (Retrofit/okhttp/RxAndroid)

倖福魔咒の 提交于 2019-12-18 15:32:14
问题 I am using Auth0, which gives me a JWT (json web token) and a refreshtoken. I use this JWT in the http headers to communicate with my backend. It could happen, that the server gives me a 403 , when it decides that the JWT has expired. In this event, I can ask Auth0 to issue me a new JWT, using the refreshtoken. It means I call the Auth0 backend, pass it the refreshtoken, and it gives me a new JWT, which I can then use in my requests. My question is, how can I efficiently write this behaviour

How to detect upload/download transfer rate in Android?

会有一股神秘感。 提交于 2019-12-18 12:46:04
问题 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 satisfied with the answers in these posts, so I am asking again. I've seen apps which display the upload transfer rate, as well as some custom ROMs like Resurrection Remix. How can I determine the

javax.net.ssl.SSLPeerUnverifiedException: Hostname not verified:

a 夏天 提交于 2019-12-18 11:47:46
问题 I am trying to use HTTPS connection with self-signed certificate. I have followed steps of creating self-signed certificate as mentioned here - Creating Self-signed certificate. Everything works fine even in browser, it only shows me a message that my certificate is signed by unknown CA. But I have problem with my FQDN(server name doesn't match) name in certificate because I have set incorrect name while generating certificate. I have regenerated it and now no such error. I need to use my