okhttp3

Retrofit Closing Response Body

守給你的承諾、 提交于 2019-12-01 15:44:22
问题 I've been getting this error: A connection to ****** was leaked. Did you forget to close a response body? So I went on and close the responses I get. response.body().close() Problem is if the response.body() is already converted to a custom class, there's no close method available. Also I tried calling raw and gives me an exception: fetchSomething.enqueue(new Callback<SomethingClass>() { @Override public void onResponse(Call<SomethingClass> call, Response<SomethingClass> response) { //Closes

File upload through okhttp3

南笙酒味 提交于 2019-12-01 14:55:08
After selecting image,doc or pdf,I want to pass them through okhttp3.How do i go about doing this? @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK && requestCode==0){ Log.d("uri data",""+data.getData()); selectedFileUri = data.getData(); fileToBeUploaded = new File(""+selectedFileUri); fileName = fileToBeUploaded.getName(); Log.d("filename",""+fileName); And in okhttp 3 RequestBody formBody = new MultipartBody.Builder() .setType(MultipartBody

File upload through okhttp3

谁都会走 提交于 2019-12-01 13:12:28
问题 After selecting image,doc or pdf,I want to pass them through okhttp3.How do i go about doing this? @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK && requestCode==0){ Log.d("uri data",""+data.getData()); selectedFileUri = data.getData(); fileToBeUploaded = new File(""+selectedFileUri); fileName = fileToBeUploaded.getName(); Log.d("filename",

HttpLoggingInterceptor for http request & response logging

我只是一个虾纸丫 提交于 2019-12-01 04:20:31
问题 I'm using retrofit2 and I need to log all request and response. Request and response works perfectly, All I need is to log those request/response, I tried almost every solution, which I found here, but did not find solution. I don't understand what's wrong is here this is my code class Factory { private final static OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); private static NetworkApi.Factory serverApi; private static HttpLoggingInterceptor interceptor = new

Java - Retrieving Result from OkHttp Asynchronous GET

。_饼干妹妹 提交于 2019-12-01 01:52:17
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.newCall(newRequest).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " +

Okhttp3 - Accept all certificates and use a certificatePinner

ぐ巨炮叔叔 提交于 2019-12-01 01:11:06
I'm trying to pin my server's self-signed certificate. My OkHttpClient takes two parameters, the first one is the ssl Socket Factory : final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @SuppressLint("TrustAllX509TrustManager") @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {} @SuppressLint("TrustAllX509TrustManager") @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {} @Override public java.security

Mock server requests Android Espresso UI Testing

梦想的初衷 提交于 2019-11-30 22:37:58
I am using Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to mock authentication responses and sign in the user before the tests are run. Is there a way make the app use mockwebserver so that isntead of making actual requests, I can use respontes enqueued on mockwebserver. So far I have: public class AuthenticationTest { @Rule public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>(Authentication.class); private Authentication activity; private MockWebServer server; @Before public void signin()

Android with Retrofit2 OkHttp3 - Multipart POST Error

一曲冷凌霜 提交于 2019-11-30 21:53:58
I am using Retrofit2 with OkHttp on Android for HTTP request. Here I am doing a POST request with document upload. I ran into error below: D/OkHttp: <-- 500 Server Error http://api.drivewealth.io/v1/documents (4289ms) D/OkHttp: Date: Tue, 11 Apr 2017 03:29:48 GMT D/OkHttp: Cache-Control: must-revalidate,no-cache,no-store D/OkHttp: Content-Type: text/html; charset=ISO-8859-1 D/OkHttp: Server: Jetty(9.2.17.v20160517) D/OkHttp: Content-Length: 9323 D/OkHttp: Connection: keep-alive D/OkHttp: <html> D/OkHttp: <head> D/OkHttp: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> D

Okhttp3 - Accept all certificates and use a certificatePinner

*爱你&永不变心* 提交于 2019-11-30 20:34:50
问题 I'm trying to pin my server's self-signed certificate. My OkHttpClient takes two parameters, the first one is the ssl Socket Factory : final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @SuppressLint("TrustAllX509TrustManager") @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {} @SuppressLint("TrustAllX509TrustManager") @Override public void checkServerTrusted(java.security.cert

Android with Retrofit2 OkHttp3 - Multipart POST Error

…衆ロ難τιáo~ 提交于 2019-11-30 17:59:16
问题 I am using Retrofit2 with OkHttp on Android for HTTP request. Here I am doing a POST request with document upload. I ran into error below: D/OkHttp: <-- 500 Server Error http://api.drivewealth.io/v1/documents (4289ms) D/OkHttp: Date: Tue, 11 Apr 2017 03:29:48 GMT D/OkHttp: Cache-Control: must-revalidate,no-cache,no-store D/OkHttp: Content-Type: text/html; charset=ISO-8859-1 D/OkHttp: Server: Jetty(9.2.17.v20160517) D/OkHttp: Content-Length: 9323 D/OkHttp: Connection: keep-alive D/OkHttp: