retrofit2

Retrofit2 + SimpleXML in Kotlin: MethodException: Annotation must mark a set or get method

半腔热情 提交于 2019-11-27 11:49:16
问题 I want to fetch XML data from API and map it to Kotlin model object by using Retrofit2 + SimpleXML in Kotlin. However, I got such as the following error message from SimpleXML. org.simpleframework.xml.core.MethodException: Annotation @org.simpleframework.xml.Element(data=false, name=, required=true, type=void) must mark a set or get method This is fetched XML data <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <response> <result code="0">Success</result> <token>XXXXXXXXXXXXXXXXXXXX<

How to log request and response body with Retrofit-Android?

折月煮酒 提交于 2019-11-27 10:35:10
I can't find relevant methods in the Retrofit API for logging complete request/response bodies. I was expecting some help in the Profiler (but it only offers meta-data about response). I tried setting the log level in the Builder, but this doesn't help me either : RestAdapter adapter = (new RestAdapter.Builder()). setEndpoint(baseUrl). setRequestInterceptor(interceptor). setProfiler(profiler). setClient(client). setExecutors(MyApplication.getWebServiceThreadPool()). setLogLevel(LogLevel.FULL). setLog(new RestAdapter.Log() { @Override public void log(String msg) { Log.i(TAG, msg); } }). build()

Retrofit and OkHttp basic authentication

我与影子孤独终老i 提交于 2019-11-27 10:10:18
问题 I am trying to add basic authentication (username and password) to a Retrofit OkHttp client. This is the code I have so far: private static Retrofit createMMSATService(String baseUrl, String user, String pass) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .client(client

Disable SSL certificate check in retrofit library

試著忘記壹切 提交于 2019-11-27 08:26:05
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.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification

How can we handle different response type with Retrofit 2?

我怕爱的太早我们不能终老 提交于 2019-11-27 05:36:36
问题 I have a webservice that returns either a list of serialized MyPOJO objects: [ { //JSON MyPOJO }, { //JSON MyPOJO } ] either an error object : { 'error': 'foo', 'message':'bar' } Using retrofit2, how can I retrieve the error ? Call<List<MyPOJO>> request = ... request.enqueue(new Callback<List<MyPOJO>>() { @Override public void onResponse(Response<List<MyPOJO>> response) { if (response.isSuccess()) { List<MyPOJO> myList = response.body(); // do something with the list... } else { // server

Retrofit 2 with only form-data

房东的猫 提交于 2019-11-27 05:23:11
问题 I am trying to make POST request using the Retrofit 2. The request type is form-data NOT application/x-www-form-urlencoded . I am only posting data not the files in the request and the response is in the form of JSON. I have tried @FormUrlEncoded, @Multipart but it is not working. I have tried following request 1. First Attempt @FormUrlEncoded @POST("XXXX") Call<PlanResponse> getPlanName(@Field(Constants.ACTION_ID) String actionId, @Field(Constants.OFFER_CODE) String offerCode); 2. Second

Retrofit2.0 gets MalformedJsonException while the json seems correct?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 04:45:53
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-30600/com.lehuo.lehuoandroid E/My Jobs: error while executing job com.google.gson.stream

Android Retrofit Design Patterns

限于喜欢 提交于 2019-11-27 04:43:29
I am using Retrofit to interact with my REST API, and was wondering whether anybody has any design suggestions. My app has the following packages: models services activities fragments The services package contains the interfaces for Retrofit. For example: public interface FooService { @FormUrlEncoded @POST("foo/do") @Headers("Content-Type: application/x-www-form-urlencoded; charset=UTF-8") Call<FooBar> do(); } Models contains...well, the different models. For example, FooBar . So far so good - just as per Retrofit documentation. I have created an API class, that handles the Retrofit build

Android pre-lollipop devices giving error “SSL handshake aborted: ssl=0x618d9c18: I/O error during system call, Connection reset by peer”

雨燕双飞 提交于 2019-11-27 04:32:17
Iam having this strange issue in which the retrofit keeps throwing me "SSL handshake aborted: ssl=0x618d9c18: I/O error during system call, Connection reset by peer" in kitkat, whereas the same code working fine in lollipop devices. Iam using an OkHttpClient client like the following public OkHttpClient getUnsafeOkHttpClient() { try { final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted( java.security.cert.X509Certificate[] chain, String authType) { } @Override public void checkServerTrusted( java.security.cert

Parse JSON array response using Retrofit & Gson

拟墨画扇 提交于 2019-11-27 04:31:38
Here is my JSONArray Response from Web service: [ { "sponsors": [ { "leg_id": "NYL000067", "type": "primary", "name": "AUBRY" }, { "leg_id": "NYL000171", "type": "cosponsor", "name": "PERRY" }, { "leg_id": "NYL000066", "type": "cosponsor", "name": "ARROYO" }, { "leg_id": "NYL000223", "type": "cosponsor", "name": "BARRETT" }, { "leg_id": "NYL000312", "type": "cosponsor", "name": "STECK" }, { "leg_id": "NYL000180", "type": "cosponsor", "name": "RIVERA" }, { "leg_id": "NYL000114", "type": "cosponsor", "name": "GOTTFRIED" }, { "leg_id": "NYL000091", "type": "cosponsor", "name": "COOK" }, { "leg_id