retrofit

Implement retryWhen logic

家住魔仙堡 提交于 2019-12-23 09:14:52
问题 I have an app which requires session (cookies) to process web calls. Im using Retrofit+RxJava . However, session could expire (Retrofit error with 401 Unauthorized status) and i want to reauthenticate (to get fresh cookies) and retry previous call in this case. How would i do it with RxJava ? My example: getServerApi().getDialogs(offset, getCookies()) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .retryWhen(observable -> {...}) // Need some logic .subscribe

Retrofit gives EOFException only the first time

别来无恙 提交于 2019-12-23 08:49:33
问题 I'm using framework Retrofit for the first time in my Android project. It handles communication with a backend. Now the strangest part is that on Android 4.4 everything works like a charm. On every version below. I get a RetrofitError type java.io.EOFException. So it fails the first time and then when I push on the retry button it works. So Why is it failing the first time? I want to fix this because it is annoying that users needs to click retry... Does someone got a solution for this? 回答1:

Getting a Unexpected JDWP Error: 103 while trying to upload an image using retrofit to an api server android?

本秂侑毒 提交于 2019-12-23 07:38:09
问题 I'm getting the following 103 error message while trying to upload an image on the api server using retrofit multipart, the api receives an api token, "_method":"PUT" and image url as parameters, on response receives the complete JSON but with the previous or default image link, the current selected image does not upload, everything else is optional, any help would be appreciated, code is listed below thanks. Also main method is POST but "_method":"PUT" parameter lets you upload the image,

android livedata make sequential call

感情迁移 提交于 2019-12-23 07:24:58
问题 I am using Retrofit, Live data. There is one situation on my project, I have to make sequence of network call. if any one fails it should return error. At present I have two live data observers to get the work done, which is not good approach so I wanted to know the better approach or sample code to handle such requirement. Note: I am not using Rxjava. View code Basic logic String id = "items/1233"; //ID which has to to be deleted if (isCustomizedItem) { viewModel.deleteEvent(id); } else {

Retrofit and Slash characters in PATH

佐手、 提交于 2019-12-23 07:23:02
问题 I am facing an issue with Retrofit and would like to find a suitable answer as the only way I can think of it is pretty ugly and not practical. Retrofit PATH annotation requires a "/" in the beginning (as you can read in this code extracted from the library source: /** Loads {@link #requestUrl}, {@link #requestUrlParamNames}, and {@link #requestQuery}. */ private void parsePath(String path) { if (path == null || path.length() == 0 || path.charAt(0) != '/') { throw methodError("URL path \"%s\"

android livedata make sequential call

这一生的挚爱 提交于 2019-12-23 07:21:06
问题 I am using Retrofit, Live data. There is one situation on my project, I have to make sequence of network call. if any one fails it should return error. At present I have two live data observers to get the work done, which is not good approach so I wanted to know the better approach or sample code to handle such requirement. Note: I am not using Rxjava. View code Basic logic String id = "items/1233"; //ID which has to to be deleted if (isCustomizedItem) { viewModel.deleteEvent(id); } else {

ArrayList Null Pointer Exception playing with Condition

偶尔善良 提交于 2019-12-23 05:39:11
问题 ArrayList NullPointerException (NPE) while fetching data for the product of Google only Here is the line where I am getting NPE : searchList.add(value); // getting NPE Log: 02-24 14:25:35.903 17269-17269/app.retrofit_chucknorries E/app.retrofit_chucknorries.MainActivity$2: ERROR: null 02-24 14:25:35.904 17269-17269/app.retrofit_chucknorries W/System.err: java.lang.NullPointerException 02-24 14:25:35.909 17269-17269/app.retrofit_chucknorries W/System.err: at app.retrofit_chucknorries

request in another request called several times with rxJava and retrofit

a 夏天 提交于 2019-12-23 05:15:28
问题 I'm using MVVM and rxJava and retrofit to send my request. I have a bottom navigation view which has 5 fragments and in one of them, I have to send a request and after it, the response is delivered, I have to send another request to my server. this is my ViewModel class : class MyViewModel: ViewModel() { val compositeDisposable = CompositeDisposable() val myFirstReqLiveData = MutableLiveData<myFirstReqModel>() val mySecondReqLiveData = MutableLiveData<mySecondReqModel>() fun getFirstReq(token

upload image in base64 format and compressed image before sending to server with retrofit?

青春壹個敷衍的年華 提交于 2019-12-23 05:05:29
问题 I've make upload image with retrofit that i follow from tutorial in internet. here are my code: AcademicClient.class @Multipart @POST("/") Call<ResponseBody> postImage(@Part MultipartBody.Part image, @Part("name")RequestBody name); MainFeed.class File file = new File(filePath); RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"),file); MultipartBody.Part body = MultipartBody.Part.createFormData("upload",file.getName(),reqFile); RequestBody name = RequestBody.create(MediaType

How to call the Image upload web service (ASP.NET ) .asmx file in android using Retrofit

一个人想着一个人 提交于 2019-12-23 04:57:13
问题 I am trying to upload an image file in the folder from android to asp.net(Web Service- .asmx file) using retrofit. I have created the web method for that and that web method is working appropriately and I tested on postman also. But when I tried to upload from android then it displays the "500 Internal Server Error" Web Method (ASP.NET .asmx file) [WebMethod] public void UploadImage_http() { var request = HttpContext.Current.Request; var photo = request.Files["photo"]; photo.SaveAs