retrofit2

GET api with Retrofit

亡梦爱人 提交于 2019-12-11 03:38:30
问题 I have a web service link which I want to hit with different customerId in the form of http://apidev.myserver.com.au:8980/TestService/rest/TestService/jobs/bycustid/customerId how do I append the value of customerId? this is my base URL : http://apidev.myserver.com.au:8980/TestService/rest/TestService/ this is what my interface for calls look like : interface CustomerJobs { @GET("jobs/bycustid/11726") Call<CustomerJobsPojo> getCustomerJobs(); } 回答1: As the doc says : interface CustomerJobs {

Getting response 403 forbidden when trying to call rest api hosted on AWS using node.js

筅森魡賤 提交于 2019-12-11 02:48:26
问题 I'm trying to call a restful API using retrofit(retrofit:2.3.0) in Android and the API calls work from the Postman and iOS but do not work for the Android. Apis working fine which does not use JWT Authorization header(Bearer auth_token) like login & signup API but when I try with Authorization header it returns 403 forbidden. I'm getting cookies header too on login and sign-up response. Here is my code; ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class); final Call

Can I use ViewModel to send data to the server?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 01:09:44
问题 Currently, I am using ViewModel to load a list of Shows in my app. Then, I display it in the main screen. It survives to configuration changes and does not provoke memory leaks since ViewModel has this features. Now I need to do something a bit different. I need to log in a user making a network call to an endpoint using retrofit 2 and rxjava 2, he will type the email and password, and then will be redirected to the MainActivity. Second, I also need to update the user information, he types

Get single JSON property value from response JSON using Retrofit 2

青春壹個敷衍的年華 提交于 2019-12-11 00:47:37
问题 I am using Retrofit library (version 2.0.2 as of this writing). I am making a GET call to a service which responds a big JSON object but I am only interested in one key:value pair in it. How can I get just that instead of writing a whole new POJO class that matches the JSON response? Example - { status_code: 34, status_message: "The resource you requested could not be found.", ..., ... } I need only status code value (34 here). Please note, I am just giving an example of this JSON object here

Retrofit: Deserializing list of objects into different types

房东的猫 提交于 2019-12-11 00:45:17
问题 Developing Android application. I'm using retrofit to get my response. Currently I have made one POJO model class, which contains fields from all types (In reality they have way more fields and their own methods, so I have simplified them here a lot). Code from Client.class : OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.readTimeout(30, TimeUnit.SECONDS); OkHttpClient okHttpClient = builder.build; Retrofit retrofit = new Retrofit.Builder() .addConverterFactory

OkHttp Authenticator sometimes does not call authenticate with multiple Retrofit instances

ⅰ亾dé卋堺 提交于 2019-12-11 00:22:45
问题 I have two different Retrofit instances for two different APIs. I also have two different OkHttp3 clients but they share the same Authenticator because the auth token is the same for both APIs. The problem is that when the token expires then sometimes (but almost always) one of the Retrofit / OkHttpClient objects will not call the Authenticator 's authenticate method on HTTP 401. It will happily make API calls and all will end with 401 and the authenticator is completely ignored. In this case

Caching error with Retrofit 2 and okhttp 3

橙三吉。 提交于 2019-12-11 00:18:46
问题 I'm trying to cache HTTP responses from my company API but it looks like the app cannot access the cache directory: W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.appname/cache/cache_file/journal.tmp W/System.err: java.net.UnknownHostException: Unable to resolve host "www.domain.com": No address associated with hostname I have followed this tutorial. Here is how I setup Retrofit (2.1.0): import lu.CompanyName.R; import lu.CompanyName.interfaces

Unable to fetch json object and array in Retrofit 2

元气小坏坏 提交于 2019-12-10 22:53:56
问题 I'm trying to parse the json from the api http://badiyajobs.com/apis/v1/roles but response.isSuccess is returning false my modal class is, package arpit.retrodemo; import java.util.List; import java.util.ArrayList; public class Modal { private List<RolesEntity> roles = new ArrayList<>(); public void setRoles(List<RolesEntity> roles) { this.roles = roles; } public List<RolesEntity> getRoles() { return roles; } public static class RolesEntity { private String id; private String role; private

Retrofit 2.0 beta 4 response get IllegalArgumentException

浪尽此生 提交于 2019-12-10 22:19:21
问题 I am using retrofit 1.9 and i created logout method as @GET("/user/logout") void logoutUser(Callback<Response> callback); logoutUser(new RequestCallback<Response>(this) { @Override public void success(Response response, Response response2) { settingsService.setUserLoggedOut(); getMainActivity().finish(); } }); i upgraded it to retrofit 2.0 beta 4 and used this code @GET("user/logout") Call<Response> logoutUser(); logoutUser().enqueue(new RequestCallback<Response>(this) { @Override public void

Retrofit2 HttpLoggingInterceptor Logcat

烂漫一生 提交于 2019-12-10 21:44:37
问题 Probably a novice question but I'm wondering where I actually catch the logs in log cat. Is there a particular place I put a log, a special regex to use etc. This is what my interceptor looks like: HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient okClient = new OkHttpClient.Builder().addInterceptor(interceptor).build(); // Retrofit setup Retrofit client = new retrofit2.Retrofit.Builder() .baseUrl(BASE_URL)