retrofit2

How to solve JSON retrofit error with Deferred Response

让人想犯罪 __ 提交于 2019-12-11 16:23:20
问题 I followed with tutorial : https://android.jlelse.eu/android-networking-in-2019-retrofit-with-kotlins-coroutines-aefe82c4d777 I need to recover data in JSON format, I get the following error message : com.squareup.moshi.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $* I looked at this answer but I don't know how to adapt it to my code : Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAY This is my interface interface LocationService { @GET("locations?countryid=fr") fun

How to add retryWhen() for limited time (Eg 3 time retries only) getting IOException

a 夏天 提交于 2019-12-11 16:07:16
问题 I am fetching response from server using 3 web API calls, but in case of getting IOException i have to retry those calls for 3 times using retryWhen(). How can I achieve that? i have tried adding below code, but not getting expected output retryWhen(new Function<io.reactivex.Observable<Throwable>, ObservableSource<?>>() { int retryCount = 0; @Override public ObservableSource<?> apply(io.reactivex.Observable<Throwable> errors) throws Exception { return errors.flatMap(new Function<Throwable,

HTTP FAILED: java.net.SocketException: Socket closed Retrofit

南楼画角 提交于 2019-12-11 15:56:34
问题 tried with multiple ways still facing this issue as I am using RxJava and Retrofit to do all my network operations. Below is my code. <-- HTTP FAILED: java.net.SocketException: Socket closed Service.kt @GET("/v1/contact/{id}") fun getContactDetails(@Path("id") id:String): Flowable<ContactDetailResponse> AccountRepositoryImpl.kt override fun contactDetails(contactId:String) { mContactResponse.loading(true) remote.getContactDetails(contactId) .performOnBackOutOnMain(scheduler) .subscribe({ data

Unable to parse gzip response from server using retrofit android

元气小坏坏 提交于 2019-12-11 15:44:17
问题 final OkHttpClient okHttpClient = new OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .addInterceptor(new GzipRequestInterceptor()) .build(); @Headers({ "Content-Type: application/json;charset=utf-8", "Accept: application/json" }) @Streaming @POST("updateContent") This is header I am using to get zipped Gzip response from the server. Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder()

Retrofit with RX runs OutOfMemory while trying to send a large BASE64

北城余情 提交于 2019-12-11 15:30:25
问题 I want to send a model throw Retrofit, which contains some standard fields and files, encoded in BASE64 format. I know, that this is a crazy way to send files, but I have a server with no backend developer. So, when I'm sending, for example, 3 pdf files 20mb each, I runs out of memory which exception like this Failed to allocate a 30544558 byte allocation with 2085152 free bytes and 26MB until OOM I figured out, that it's a problem in parse of base64 string, which I'm already have in memory

Unable to POST my data using retrofit android using kotlin

旧巷老猫 提交于 2019-12-11 15:16:39
问题 I am new to android studio and kotlin. I have trying to post my data(object) onto the server but I'm getting a 404 response code. My retrofit: object RetrofitClient { private var OurInstance : Retrofit?=null val client = OkHttpClient.Builder() val instance:Retrofit get() { if (OurInstance==null) { OurInstance =Retrofit.Builder() .baseUrl("http://coreapi.imagin8ors.org:8080/") .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(

Retrofit Observable response to LiveData object using subscribe

微笑、不失礼 提交于 2019-12-11 15:13:00
问题 I have inherited this project that was using retrofit incorrectly with LiveData by trying to convert responses to LiveData immediately. I am in the middle of trying to refactor, but am getting stuck with converting an RxJava Observable to a LiveData object in the ViewModel. Here is what I have so far: Retrofit Service interface Service { @POST("user/login") fun postLogin(@Body body: LoginBody) Observable<ApiResponseWrapper<LoginRemote>> } As you can see, Observable wraps an ApiResponseWrapper

RxJava 2 Nested Network Requests

我与影子孤独终老i 提交于 2019-12-11 14:58:44
问题 in the app I am currently working on I use retrofit to create an Observable <ArrayList<Party>> . Party has a hostId field as well as a field of type User which is null at the point of creation by Retrofits GsonConverter. I now want to use hostId to make a second request getting the user from id and adding the User to the initial Party . I have been looking into flatmap but I haven't found an example in which the first observable's results are not only kept but also modified. Currently, to get

Retrofit POST request response.isSuccessful() returning false

。_饼干妹妹 提交于 2019-12-11 14:44:20
问题 I am trying to make POST request using Retrofit2. But I am in a situation where the response.isSuccessful() is returning false and I do not know how to debug it. I checked my backend's logs and there are no errors, nothing. I made sure that the request's URL is correct, also that all the parameters are right. What I am doing wrong? For me it seems that the request even doesn't make it to my server. This is what I do: I have class User with getters and setters: public class User {

Android Studio: retrofit2: multipart connection failure with image and strings

我只是一个虾纸丫 提交于 2019-12-11 12:27:12
问题 private void Dialog_profile_pic() { // create upload service client File file = new File(selectedImagePath); // create RequestBody instance from file RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); // MultipartBody.Part is used to send also the actual file name MultipartBody.Part body = MultipartBody.Part.createFormData("memFile", file.getName(), requestFile); // add another part within the multipart request RequestBody description = RequestBody