retrofit2

retrofit 2 / okhttp3 clear cookies

匆匆过客 提交于 2019-12-13 07:39:27
问题 I'm using retrofit and cookieJar okBuilder.cookieJar(getCookieJar()); Everything works great, but sometimes I want to clear cookies. How can I do it in retrofit or okhttp? In JavaNetCookieJar are only 2 public methods: cookieJar.loadForRequest() cookieJar.saveFromResponse(); 回答1: CookieHandler cookieHandler = new CookieManager( new PersistentCookieStore(ctx), CookiePolicy.ACCEPT_ALL); // init okhttp 3 logger HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel

Android: RESTfull API called from `retrofit 2` says `Method Not Allowed`

十年热恋 提交于 2019-12-13 07:07:50
问题 I have developed a web service using Java and Jersey. Now I am trying to connect into it, call its methods and get data, using android. Below is the related part of the web service. import bean.PatientBean; import bean.UserBean; import db.PatientImpl; import db.PatientInterface; import db.UserImpl; import db.UserInterface; import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws

Retrofit - Send request body as array or number

限于喜欢 提交于 2019-12-13 05:16:19
问题 I'm using Retrofit 2 and I need to send request body. The problem is somehow the value is converted to string. On the example below, you can see that items and totalPrice which should be array and number respectively are converted to string. { cashierId: 'fff7079c-3fc2-453e-99eb-287521feee63', items: '[{"amount":3,"id":"602a79e3-b4c1-4161-a082-92202f92d1d6","name":"Play Station Portable","price":1500000.0}]', paymentMethod: 'Debt', totalPrice: '4500000.0' } The desired request body is {

Adding authorization header interface android retrofit

烈酒焚心 提交于 2019-12-13 04:01:23
问题 I'm using retrofit library for solving my tasks connected with requests to server. I have got parameters from server developers: URL https://server/v1/message/list Edit this section Method GET Edit this section HTTP Headers Authorization:Bearer $access_token Edit this section URL Params type 0 - for received messages 1 - for sent messages Optional: offset In normal case you should not pass this parameter manually. It uses in previous/next urls, nevertheless it can takes values > 1 for getting

Retrofit v2.4.0 is not sending the If-Modified-Since header

匆匆过客 提交于 2019-12-13 03:52:22
问题 This may be a very basic question, but I've ran out of ideas. Retrofit v2.4.0 is not sending the If-Modified-Since header, as a result caching is not working. I'm polling the server several times a day to see if is there any updated data, hence the need for If-Modified-Since header. (push notifications may be implemented in a new release) Based on this article, the setup is extremely easy: https://futurestud.io/tutorials/retrofit-2-activate-response-caching-etag-last-modified I've read

Blank screen with RecyclerView No adapter attached

房东的猫 提交于 2019-12-13 03:46:38
问题 I'm tying to parse JSON in recyclerview. App compiles fine but it's outputting empty/blank screen BlogAdapter.kt class BlogAdapter(private val blogList: List<Blog>) : RecyclerView.Adapter<BlogAdapter.ViewHolder>() { override fun getItemCount()= blogList.size private var mContext: Context? = null override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { this.mContext=parent.context; return ViewHolder( LayoutInflater.from(parent.context).inflate( R.layout.character_item,

android retrofit add custom header

做~自己de王妃 提交于 2019-12-13 03:40:14
问题 i using retrofit2 and want add some header using OkHttp3 addInterceptor but not working this is my code OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); Request request = original.newBuilder() .removeHeader("Authorization") .removeHeader("Content-type") .removeHeader("User-Agent") .addHeader("Content-type", "application/x-www-form

Retrofit --> java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

假如想象 提交于 2019-12-13 03:39:35
问题 None of the posts i found have helped me understand what im supposed to do. Stuck on this for quite a while so asking here. I want the List of IN and OUT names as "in" and "out" are json arrays. The error shows up as exception in OnFailure of response. getUsers() is in main activity. private void getUsers() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); APIInterface api = retrofit.create(APIInterface.class); Call

Parse data from OpenWeatherMap, using retrofit2 and rxJava2

不想你离开。 提交于 2019-12-13 03:34:52
问题 I've started to learn Retrofit and RxJava, and I've decided to create weatherApp. Now my goal is to retrieve weather data from OpenWeatherMap Api. Here's my code: For api: package com.example.aldres.workingwithapis.Api; import com.example.aldres.workingwithapis.models.WeatherData; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; public interface Api { @GET("weather?") Observable<WeatherData> getWeatherData(@Query("q") String city); } Also code for my WeatherData

Image upload using retrofit2 Put method

醉酒当歌 提交于 2019-12-13 03:16:27
问题 I am new to retrofit2. I want upload image through api service as a file. I have tried with postman by selecting a file and found its working. But through mobile how can I upload the image file. Here is the Header section of Api --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ In the body section I am having, "picture", "name", "email" and "phone" I am trying like, i have created a class with body parameters UpdateRequest Class public class