retrofit2

Retrofit2 Android: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

天大地大妈咪最大 提交于 2019-11-26 19:59:35
I know this is not the first time someone asking about this problem but with Retrofit2 I can't find the right solution to my problem. I followed a online tutorial and it worked just fine. When I applied same code to my own endpoint i get this exception: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ I don't know how to solve this. Interface: public interface MyApiService { // Is this right place to add these headers? @Headers({"application-id: MY-APPLICATION-ID", "secret-key: MY-SECRET-KEY", "application-type: REST"}) @GET("Music") Call

Android:dynamically pass model class to retrofit callback

醉酒当歌 提交于 2019-11-26 19:59:21
问题 In retrofit to map json response to pojo usually we do this @POST Call<User> getDataFromServer(@Url String url, @Body HashMap<String,Object> hashMap); ApiCalls api = retrofit.create(ApiCalls.class); Call<User> call = api.getDataFromServer(StringConstants.URL,hashMap); call.enqueue(new Callback<User>() { //Response and failure callbacks } where User is my Pojo class. But for every other request i need to make different pojo and write same code for retrofit call.I want to make a single method

how to get json response using retrofit

情到浓时终转凉″ 提交于 2019-11-26 18:37:45
问题 {"status":"0","message":"Login unsuccessful :( This account doesn't exist or the email is not verified yet! try asking admin for activation and then logging in ;)"} Here Is My Url http://zeenatkhanniazai.com/services/login.php Login class and Interface public static String BASE_URL="http://zeenatkhanniazai.com/services/"; public static loginServices loginn=null; public static loginServices Login(){ if (loginn == null ){ Retrofit retrofit=new Retrofit.Builder().baseUrl(BASE_URL)

Chaining requests in Retrofit + RxJava

余生颓废 提交于 2019-11-26 18:25:34
问题 I have 2 APIs that I want to make request to in sequence and store their data in SQLite. First I want to make request to API A and store its data in SQL table a . Then make request to API B and store its data in table b and some data in table a_b . The data stored in a_b is from request B alone. How can I do this using RxJava. I read somewhere about using flatMap for this, something like this apiService.A() // store in DB here? How? maybe use map()? .flatMap(modelA -> { // or maybe store

Retrofit - Multipart request: Required MultipartFile parameter 'file' is not present

北城以北 提交于 2019-11-26 17:44:51
I'm trying to send file on server using Retrofit2. I do everything according documentation, but always get 400 server error. I'm tried to do like this: RequestBody body = RequestBody.create(MediaType.parse("image/png"), photo); //.......... @Multipart @POST(ADD_PHOTO) Observable<HPSPhotoResponse> addPhoto(@Part("file") RequestBody file); ...and like this: MultipartBody.Part part = MultipartBody.Part.createFormData("file", "file", body); //........... @Multipart @POST(ADD_PHOTO) Observable<HPSPhotoResponse> addPhoto(@Part("file") MultipartBody.Part files); does't matter. Result is always the

Retrofit2.0 gets MalformedJsonException while the json seems correct?

泪湿孤枕 提交于 2019-11-26 17:28:38
问题 I am using retrofit:2.0.0-beta4 for my android app. I tried to add a user with Retrofit, the user is correctly created in Database, however I got the following error: 03-14 06:04:27.731 30572-30600/com.lehuo.lehuoandroid D/OkHttp: CALLING POST SP_User_CreateUser....your new user_id:48 {"data":{"user_id":"48","nickname":null,"password":null,"status":null},"status":1,"msg":"OK"} 03-14 06:04:27.731 30572-30600/com.lehuo.lehuoandroid D/OkHttp: <-- END HTTP (147-byte body) 03-14 06:04:27.732 30572

Retrofit 2: Get JSON from Response body

余生颓废 提交于 2019-11-26 16:04:00
I want to get string json from my api using retrofit 2, I have no problem when using retrofit 1 to get this json but using retrofit 2 returns null for me. This is what my json looks like {"id":1,"Username":"admin","Level":"Administrator"} This is my API @FormUrlEncoded @POST("/api/level") Call<ResponseBody> checkLevel(@Field("id") int id); This is how my code looks like Retrofit retrofit = new Retrofit.Builder() .baseUrl(Config.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); Api api = retrofit.create(Api.class); Call<ResponseBody> call = api.checkLevel(1); call.enqueue

Disable SSL certificate check in retrofit library

感情迁移 提交于 2019-11-26 13:52:37
问题 I am using retrofit in android to connect with server. public class ApiClient { public static final String BASE_URL = "https://example.com/"; private static Retrofit retrofit = null; public static Retrofit getClient() { if (retrofit==null) { retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); } return retrofit; } } This is my dev. server and I want to disable certificate check. How can I implement in this code? ERROR: javax.net

Retrofit 2.0 how to get deserialised error response.body

旧城冷巷雨未停 提交于 2019-11-26 12:21:08
问题 I\'m using Retrofit 2.0.0-beta1 . In tests i have an alternate scenario and expect error HTTP 400 I would like to have retrofit.Response<MyError> response but response.body() == null MyError is not deserialised - i see it only here response.errorBody().string() but it doesn\'t give me MyError as object 回答1: I currently use a very easy implementation, which does not require to use converters or special classes. The code I use is the following: public void onResponse(Call<ResponseBody> call,

Set dynamic base url using Retrofit 2.0 and Dagger 2

可紊 提交于 2019-11-26 12:18:48
问题 I\'m trying to perform a login action using Retrofit 2.0 using Dagger 2 Here\'s how I set up Retrofit dependency @Provides @Singleton Retrofit provideRetrofit(Gson gson, OkHttpClient client) { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create(gson) .client(client) .baseUrl(application.getUrl()) .build(); return retrofit; } Here\'s the API interface. interface LoginAPI { @GET(relative_path) Call<Boolean> logMe(); } I have three different base urls