retrofit2

Getting Request body content using Retrofit 2.0 POST method

一曲冷凌霜 提交于 2019-12-21 03:55:06
问题 I have a requirement to get a request body and to perform some logic operations with Retrofit 2.0 before doing enque operation. But unfortunately I am not able to get the post body content from my service call. At present after searching a lot I found only one solution like logging the request that I am posting using Retrofit 2.0 from this method by using HttpLoggingInterceptor with OkHttpClient . I am using the following code to log the request body in the Android Logcat:

InterruptedIOException while using Retrofit2 with rx when retryOn

喜你入骨 提交于 2019-12-20 23:20:10
问题 I'm using retrofit 2 with rx-android I have quite complex retry logic, which partially works . I cut off irrelevant code to simplify it. Here it is: public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>>, Constants { @Override public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts.flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { int statusCode = 500; if (throwable

java.lang.NumberFormatException: Expected an int but was 0.6 at line 1 column 8454

只谈情不闲聊 提交于 2019-12-20 20:35:14
问题 I'm using the retrofit library for my calls in a demo project. I received the following error: java.lang.NumberFormatException: Expected an int but was 0.6 at line 1 column 8454 path $.result.results.ads[2].acres I under stand that this is down to GSON. I will show you the JSON it's getting caught in: { "ad_id":739580087654, "property_type":"site", "house_type":"", "selling_type":"private-treaty", "price_type":"", "agreed":0, "priority":2, "description":"Beautiful elevated 0.6 acre site -

Detect if OkHttp response comes from cache (with Retrofit)

那年仲夏 提交于 2019-12-20 17:41:32
问题 Is there a way to detect if a Retrofit response comes from the configured OkHttp cache or is a live response? Client definition: Cache cache = new Cache(getCacheDirectory(context), 1024 * 1024 * 10); OkHttpClient okHttpClient = new OkHttpClient.Builder() .cache(cache) .build(); Api definition: @GET("/object") Observable<Result<SomeObject>> getSomeObject(); Example call: RetroApi retroApi = new Retrofit.Builder() .client(okHttpClient) .baseUrl(baseUrl) .addCallAdapterFactory

How to use AutoValue with Retrofit 2?

佐手、 提交于 2019-12-20 10:48:30
问题 I've got AutoValue (and the android-apt plugin) working in a project, and I'm aware of Ryan Harter's gson extension for AutoValue, but how do I hook Retrofit 2 up to use the extension and factory method on the abstract class? String grantType = "password"; Call<SignIn> signInCall = retrofitApi.signIn(email, password, grantType); signInCall.enqueue(callback); eg here I would like to use AutoValue with the SignIn JSON model object to enforce immutability but how do I hook up Retrofit (or

Retrofit 2 HTTP method annotation is required (e.g., @GET, @POST, etc.)

十年热恋 提交于 2019-12-20 10:39:41
问题 What's wrong with my Retrofit configuration? I'm having this error when I'm adding Basic Authentication with my OkHttpClient but when I used the default client without Interceptor it's working. Or is there something wrong with my Gradle Dependencies..? E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalArgumentException : HTTP method annotation is required (e.g., @GET, @POST, etc.). for method APIService.getRegAccrDetails at retrofit.Utils.methodError(Utils.java:177) at retrofit.Utils

Retrofit 2 - Elegant way of adding headers in the api level

懵懂的女人 提交于 2019-12-20 09:21:13
问题 My Retrofit 2 ( 2.0.2 currently) client needs to add custom headers to requests. I'm using an Interceptor to add these headers to all requests: OkHttpClient httpClient = new OkHttpClient(); httpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { final Request request = chain.request().newBuilder() .addHeader("CUSTOM_HEADER_NAME_1", "CUSTOM_HEADER_VALUE_1") .addHeader("CUSTOM_HEADER_NAME_2", "CUSTOM_HEADER_VALUE_2") ...

android retrofit ,post whole Pojo using this format

孤人 提交于 2019-12-20 06:39:55
问题 I want to post this kind of request in retrofit2 so if someone have idea about it then it would be great help of mine. reqObject={"task":"singleUser","taskData":{"userID":"1"}} 回答1: Yes, good Question It is some what not understandable for Beginner . So I combining some Answers for you. first step make your Json -> model class (or POJO class) From GsonFormattor plugin This plug-in convert your Json to Model class Pojo genrator Go to this link , copy and paste Your Json and simply make your

Dagger generating multiple instances of retrofit interceptor

梦想的初衷 提交于 2019-12-20 04:43:05
问题 I am new to Dagger and Retrofit. I am having issue where multiple instances of retrofit custom interceptor are being generated despite declared singleton in dagger module. I only require one instance. Dagger Module @Module public class ApiModule { private Config config; public ApiModule(Config config) { this.config = config; } @Provides @Singleton public OkHttpClient.Builder provideOkHttpClient() { return new OkHttpClient.Builder(); } @Provides @Singleton public

Retrofit 2.0.2 image upload using multipart

二次信任 提交于 2019-12-20 04:16:58
问题 I am new for Retrofit I wanna to upload single image with different params like name,dob,mobile. i don't know where i am wrong Please guide me. I follow this LINK Here is my code interface @Multipart @POST("signup") Call<ResponseBody> getSignup(@Part("name") RequestBody name, @Part("email") RequestBody email, @Part("dob") RequestBody dob, @Part("phone") RequestBody phone, @Part("IMEI") RequestBody IMEI, @Part MultipartBody.Part file); upload code // create RequestBody instance from file