okhttp3

JSON Response Using Retrofit on Android

戏子无情 提交于 2019-12-13 07:49:47
问题 I'm able to get JSON response using OkHttp3, and I want to use Retrofit to parse the response to get the name and the image from it. I looked into Retrofit website and some tutorials, but still the process not clear. Here is my OkHttp3 code to get JSON response: Request request = new Request.Builder().url(url).build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { e.printStackTrace(); } @Override public void onResponse(Call call,

retrofit 2 / okhttp3 clear cookies

匆匆过客 提交于 2019-12-13 07:39:27
问题 I'm using retrofit and cookieJar okBuilder.cookieJar(getCookieJar()); Everything works great, but sometimes I want to clear cookies. How can I do it in retrofit or okhttp? In JavaNetCookieJar are only 2 public methods: cookieJar.loadForRequest() cookieJar.saveFromResponse(); 回答1: CookieHandler cookieHandler = new CookieManager( new PersistentCookieStore(ctx), CookiePolicy.ACCEPT_ALL); // init okhttp 3 logger HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel

Retrofit v2.4.0 is not sending the If-Modified-Since header

匆匆过客 提交于 2019-12-13 03:52:22
问题 This may be a very basic question, but I've ran out of ideas. Retrofit v2.4.0 is not sending the If-Modified-Since header, as a result caching is not working. I'm polling the server several times a day to see if is there any updated data, hence the need for If-Modified-Since header. (push notifications may be implemented in a new release) Based on this article, the setup is extremely easy: https://futurestud.io/tutorials/retrofit-2-activate-response-caching-etag-last-modified I've read

Is manually inserting data into a okhttp cache safe?

北城余情 提交于 2019-12-13 02:52:28
问题 I'm trying to preload a okhttp cache with data from a REST endpoint e.g., persons/1,2,3 that returns the same data as person/1 using an interceptor. It works but it uses cache().put$okhttp(resp) . Is it safe to use cache().put$okhttp(resp) to manipulate the okhttp cache like done below? String json = encoder.writeValueAsString(object); Request newRequest = new Request.Builder().url(url).build(); ResponseBody body = ResponseBody .create(MediaType.parse("application/json"), json); Response resp

OKHttp handle 302

和自甴很熟 提交于 2019-12-12 21:23:06
问题 Every time I perform a OKHttp Post request on this site, the response code is 302 and the response body is: <html> <head> <title>Object moved</title> </head> <body> <h2>Object moved to <a href="/GradebookSummary.aspx">here</a>. </h2> </body> </html> Here is my code: OkHttpClient client = new OkHttpClient().newBuilder() .followRedirects(false) .followSslRedirects(false) .build(); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); RequestBody body = RequestBody.create

Retrofit2 Okhttp3 catch TimeOut

女生的网名这么多〃 提交于 2019-12-12 18:36:15
问题 I got a client like this: public enum RestClient { INSTANCE; private static final int CONNECTION_TIMEOUT = 10; private static final int READ_TIMEOUT = 30; private static final int WRITE_TIMEOUT = 30; private final Rest restClient; private RestClient() { restClient = new Retrofit.Builder() .baseUrl(App.getContext().getResources().getString(R.string.EP)) .addConverterFactory(JacksonConverterFactory.create()) .client(new okhttp3.OkHttpClient.Builder() .connectTimeout(CONNECTION_TIMEOUT, TimeUnit

OkHttp returning unreadable characters

瘦欲@ 提交于 2019-12-12 10:49:23
问题 I am sending a request to server and getting Collection + Json in responce. Every thing is perfect in PostMan. But when I am doing same things in code using OKHTTP, I am getting some unreadable characters. Here is my code OkHttpClient client = new OkHttpClient(); requestBody = new FormBody.Builder() .add("email", email) .add("password", psd) .build(); Request request = new Request.Builder() .url(url) .addHeader("Accept", "application/vnd.collection+json") .addHeader("Accept-Encoding", "gzip")

OKhttp : SSLProtocolException: SSL handshake terminated

蹲街弑〆低调 提交于 2019-12-12 09:42:29
问题 I'm trying to figure out why sometimes I get this error javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x60d46c90: Failure in SSL library, usually a protocol error error:1409443E:SSL routines:SSL3_READ_BYTES:tlsv1 alert inappropriate fallback (external/openssl/ssl/s3_pkt.c:1256 0x60d57f40:0x00000003) the code that makes this request: private <T> void send(final String url, final Map<String, String> args, final RequestCallback<T> callback, final Parser<T> pParser, final

A separate thread freezes while sending HTTP sequests

♀尐吖头ヾ 提交于 2019-12-12 06:46:51
问题 I'm trying to build a remote control Android app and keep failing to use the network properly. The commands are sent in a separate thread with a delay of approximately 100 ms (plus sending) using HTTP ( okhttp3 ). The problem is the app sometimes freezes the transmittion printing something like this to logcat : 03-29 02:18:31.249 25191-25191/com.example.control D/CommandSender: http://192.168.1.185/drive?m1s=988&m2s=927&dir=ff s: 6557 f: 0 03-29 02:18:31.259 25191-25191/com.example.control D

Upload picture to server using retrofit 2

女生的网名这么多〃 提交于 2019-12-12 04:03:59
问题 First of all lets look to the code: public interface ApiInterface { @Multipart @POST("my/files/photo/") Call<FileUploadResponse> uploadPhoto(@Header("authorization") String auth, @Part MultipartBody.Part file, @Part("file-type") RequestBody fileType); } I'm calling this interface like this: RequestBody body = RequestBody.create(MediaType .parse(getContentResolver().getType(fileUri)), file); MultipartBody.Part avatarBody = MultipartBody.Part .createFormData(data, file.getName(), body);