retrofit

Retrofit multiple POST params

纵然是瞬间 提交于 2020-01-01 08:43:25
问题 I'm trying to submit a call to a server that requires 2 sets of information, this is my interface: @POST("/venues/get-by-location") void getByLocation(@Body Coordinates coordinates, @Body MaxDistanceBody maxDistance, Callback<MyCallback> callback); but I receive this error: " Multiple @Body method annotations found." How can I send multiple objects in one Post request? Thanks! 回答1: Maybe this can help: @Multipart @POST("/venues/get-by-location") void getByLocation(@Part("coordinates")

HTTP/2 protocol not working with okhttp

Deadly 提交于 2020-01-01 08:26:07
问题 I am using Retrofit 1.9 with okhttp 2.4.0. So far we have SPDY protocol disabled on server side (I checked it by this ). And enabled protocol on server side is HTTP/2 (I checked it by this). So I was thinking that okhttp will try to make an api call using HTTP/2 (latest one protocol) but it's using HTTP/1.1 on android device 4.2.2 samsung S4 - D/Retrofit : OkHttp-Selected-Protocol: http/1.1 Someone told me that android device doesn't support SPDY until 5.0 (I don't have any proof), so that

HTTP/2 protocol not working with okhttp

孤者浪人 提交于 2020-01-01 08:26:02
问题 I am using Retrofit 1.9 with okhttp 2.4.0. So far we have SPDY protocol disabled on server side (I checked it by this ). And enabled protocol on server side is HTTP/2 (I checked it by this). So I was thinking that okhttp will try to make an api call using HTTP/2 (latest one protocol) but it's using HTTP/1.1 on android device 4.2.2 samsung S4 - D/Retrofit : OkHttp-Selected-Protocol: http/1.1 Someone told me that android device doesn't support SPDY until 5.0 (I don't have any proof), so that

How do you prevent Retrofit from automatically following a 302

巧了我就是萌 提交于 2020-01-01 08:04:22
问题 I have an authentication call that i'm trying to make using Retrofit on Android. The call returns a 302 to either a success or failure page. The original 302 response brings back a session cookie needed to maintain authentication on success, however Retrofit is automatically handing the request off to the redirect url before I get a chance to consume the cookie. Is there a way to prevent following the redirect? Or is there a way to write a response handler on Retrofit that can add the

Retrofit: How to send a POST request with constant fields?

蹲街弑〆低调 提交于 2020-01-01 07:56:06
问题 I want to sent a simple POST request with one actual parameter: @POST("/token") @FormUrlEncoded void extendSession(@Field("refresh_token")final String refreshToken); But this request should also send some constant values requested by the server such as client_id , client_secret and grant_type which are constant and should not be part of the application API. What is the best way to do this? 回答1: It is matter of your approach. If you have the constants you can build a default Map of values

Retrofit - android.os.NetworkOnMainThreadException

送分小仙女□ 提交于 2020-01-01 07:31:08
问题 I am using Retrofit 2 to get json and parse it to POJO. My purpose is getting one value of that object. compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' My REST client: public interface MyClient { @GET("/part1/part2") Call<MyItem> getMyItem(@Query("param1") String param1, @Query("param2") String param2, @Query("param3") String param3); } Here I found great great tool to create service: public class ServiceGenerator { public

Modify response body retrofit 2.2 interceptor

邮差的信 提交于 2020-01-01 06:56:20
问题 I'm developing an app using Retrofit 2 to request to API. This API is in ASP.NET and it is zipping with GZip and encoding to Base64, like the code below: private static string Compress(string conteudo) { Encoding encoding = Encoding.UTF8; byte[] raw = encoding.GetBytes(conteudo); using (var memory = new MemoryStream()) { using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress, true)) { gzip.Write(raw, 0, raw.Length); } return Convert.ToBase64String(memory.ToArray()); } }

what is the difference between retrofit synchronous and asynchronous request? which one is better and why?

对着背影说爱祢 提交于 2020-01-01 06:55:10
问题 I have really searched for this every where, I can make both synchronous and asynchronous data requests, but I can't actually understand which is asynchronous with what? and what is sync with what? 回答1: call.execute() runs the request on the current thread. call.enqueue(callback) runs the request on a background thread, and runs the callback on the current thread. You generally don't want to run call.execute() on the main thread because it'll crash, but you also don't want to run call.enqueue

OkHttp SSLHandshakeException SSL handshake aborted Failure in SSL library, a protocol error

丶灬走出姿态 提交于 2020-01-01 04:57:18
问题 04-23 17:17:38.434 21599-21956/ D/NativeCrypto: ssl=0x0 NativeCrypto_SSL_interrupt 04-23 17:17:38.435 21599-21956/ D/OkHttp: <-- HTTP FAILED: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x635d8808: Failure in SSL library, usually a protocol error error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:744 0x5e6c46fd:0x00000000) Android lower version devices (4.1 - 4.4) gives SSL

MockWebServer and Retrofit with Callback

∥☆過路亽.° 提交于 2020-01-01 02:35:24
问题 I would like to simulate network communication by MockWebServer. Unfortulatelly retrofit callbacks are never invoking. My code: MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); server.play(); RestAdapter restAdapter = new RestAdapter.Builder().setConverter(new MyGsonConverter(new Gson())) .setEndpoint(server.getUrl("/").toString()).build(); restAdapter.create(SearchService.class).getCount(StringUtils.EMPTY, new Callback