retrofit

Upload file with Retrofit 2

…衆ロ難τιáo~ 提交于 2020-01-01 00:47:26
问题 I trying to do that a few days, and I really did everything.. Here is how request looks in Postman: I am sure, that all GET parameters were writing correctly. The problem in how I sending a file to upload, I suppose. Map<String, RequestBody> map = new HashMap<>(); File file = new File("/storage/emulated/0/ConstructSecure/d1940b05-76d1-4d98-b4b4-b04b8247c8cb.png"); RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file); String fileName = file.getName(); map.put(

Android: Polling a server with Retrofit

痞子三分冷 提交于 2019-12-31 16:35:29
问题 I'm building a 2 Player game on Android. The game works turnwise, so player 1 waits until player 2 made his input and vice versa. I have a webserver where I run an API with the Slim Framework. On the clients I use Retrofit. So on the clients I would like to poll my webserver (I know it's not the best approach) every X seconds to check whether there was an input from player 2 or not, if yes change UI (the gameboard). Dealing with Retrofit I came across RxJava. My problem is to figure out

How do I get Response body when there is an error when using Retrofit 2.0 Observables

吃可爱长大的小学妹 提交于 2019-12-31 08:55:34
问题 I am using Retrofit 2.0 to make api calls that return Observables. It all works good when the call went through fine and the response is as expected. Now let's say we have an error response, it throws an onError. I would like to read the response body even when it is an Error. Example @FormUrlEncoded @POST("tokenLogin") Observable<LoginResponse> loginWithToken( @Field("token") String pin ); When the request and response are valid, I get the right observable and onError is being called as

Retrofit 2 without Model Class

南楼画角 提交于 2019-12-31 05:31:10
问题 i want to ask about Retrofit 2.0 all this time, i knew Retrofit only with GSON Converter and get the object. But i dont know how to get the data with API like this https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty i'm trying to display all top stories and get the object after i load all the top stories first. i only know with old school style like this: http://pastebin.com/JMpwjH8H 回答1: I'm pretty sure for your example you can just set the response type as a list of Integers

retrofit and orm library throw StackOverflow

江枫思渺然 提交于 2019-12-31 04:18:07
问题 I try to use 2 libraries: square/Retrofit - Rest client satyan/sugar - db orm retrofit use gson , so do class public class Book{ String name; public Book(String name) { this.name = name; } } ok, retrofit succesfully get data from server and put in our Book class. now i want save this data. for use orm need extend parent class public class Book extends SugarRecord<Book>{ String name; public Book(String name) { this.name = name; } } but after extend the parent class, retrofit cannot parse json.

moshi custom qualifier annotation to serialise null on one property only

纵然是瞬间 提交于 2019-12-31 03:18:46
问题 I'd like to serialise null for only one property in my JSON body that is going on a PUT. I don't want to serialize null for any other types in the object. Model class is like this @Parcel class User @ParcelConstructor constructor(var college: College?, var firstname: String?, var lastname: String?, var email: String?, var active: Boolean = true, var updatedAt: String?, var gender: String?, var picture: String?, var id: String?, @field: [CollegeField] var collegeInput: String?, @field:

what does Method getResources not annotated with request type (e.g., GET, POST) mean?

依然范特西╮ 提交于 2019-12-31 01:27:20
问题 private interface ResourcesApi { @POST("/synchronize") void getResources(@Body Map<String, Map<String, Object>> map, Callback<DataModel> callback); } with calling code: mApi.getResources(data, this); The class implements Callback so success/failure are defined. STACKTRACE: 03-09 18:05:15.182 28570-28746/? E/AndroidRuntime﹕ FATAL EXCEPTION: pool-2-thread-1 java.lang.IllegalStateException: Method getResources not annotated with request type (e.g., GET, POST). at retrofit.RestMethodInfo

Simple framework skip soap envelope and body

二次信任 提交于 2019-12-30 18:55:08
问题 I'm using RetroFit and Simple XML Framework in Android to model a SOAP response that looks like this: XML: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <BuslocationResponse xmlns="AT_WEB"> <Version>1.0</Version> <Responsecode>0<

Simple framework skip soap envelope and body

帅比萌擦擦* 提交于 2019-12-30 18:55:07
问题 I'm using RetroFit and Simple XML Framework in Android to model a SOAP response that looks like this: XML: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <BuslocationResponse xmlns="AT_WEB"> <Version>1.0</Version> <Responsecode>0<

How to Pass the image in android using Retrofit?

﹥>﹥吖頭↗ 提交于 2019-12-30 15:42:00
问题 Hello i am working on upload image file using retrofit. Can any one have idea how to pass in 回答1: You need pass mulitypart object in retrofit: MultipartBody.Part carImage = null; if (!TextUtils.isEmpty(imagePath)) { File file = FileUtils.getFile(getContext(), imagePath); // create RequestBody instance from file final RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); // MultipartBody.Part is used to send also the actual file name carImage =