草庐IT

RetroFit

全部标签

android - 使用 Retrofit 批量请求

我想使用Retrofit执行批量请求。它有什么好的方法,如何实现它?基本上我要做的是替换URL查询部分中的一些字符(替换block只允许在URL的路径部分中使用@Path注释)。这是我的问题的伪代码。@GET("/v2/multi?requests=/users/self,/venues/search?client_id={client_id}&client_secret={client_secret}&v={v}&ll={ll}&intent={intent}&limit={limit}")ProfileSearchVenuesResponsesearchVenuesAndProfi

android - Retrofit 2.0 如何在不转换的情况下获取 JSON 对象?

我需要从REST服务器下载json对象而不用GSON转换。但不明白如何在Retrofit2.0bata1中制作 最佳答案 只需使用JsonElement作为您的pojo。例如在您的FlowerApi界面中:@GET("/flower")CallgetFlowers();在你的主类中:CallgetFlowersCall=httpApiClass.getFlowers();getFlowersCall.enqueue(newCallback(){@OverridepublicvoidonResponse(Responserespons

android - 如何在 Retrofit Callback 中调用 Intent ?

我想在Retrofit调用的我的Web服务的成功回调中显示一个新Activity。而且我很难找到有关如何使用Retrofit回调结果启动新Activity的示例。这是一个好方法吗?我必须先清理一些东西吗?publicvoidvalidate(Viewview){RetrofitWebServices.getInstance().webserviceMethod(params,newCallback(){@Overridepublicvoidsuccess(MyObjectobject,Responseresponse){IntentbarIntent=newIntent(FooActi

android - RxJava 替代 map() 运算符来保存发出的项目

我使用Retrofit与RESTAPI交互,RxJava操作我收到的数据。在下面的代码fragment中,我进行了一次API调用,并使用map运算符保存我收到的数据,然后再继续对流进行其他操作。retrofitApi.registerDevice(mDevice).map(newFunc1(){@OverridepublicDevicecall(Devicedevice){//Theonlypurposeofthemap()operator//istosavethereceiveddevice.magicBox.saveDeviceId(device.getId());returnde

android - 将 json 映射到改造对象 (GSON)

我从服务器得到的Json是:{"data":[{"id":1,"url":"http://example.com/image1"},{"id":2,"url":"http://example.com/image2"},{"id":3,"url":"http://example.com/image3"}]}我的映射类是publicclassRepository{privateListevents;}虽然我从改造中获得了成功,但我无法将其映射到我的对象。我还有类Event带有intid和Stringurl。 最佳答案 改成这样publi

android - Retrofit+Okhttp.HTTP 504 Unsatisfiable Request (only-if-cached)

我使用POST请求访问服务器并且在从服务器获取数据时不要向服务器发送数据。@POST("Index/getListShopsInfo")ObservablegetListShopsInfo();我想为我的数据添加一个本地缓存。publicclassCacheInterceptorimplementsInterceptor{privateContextmContext;publicCacheInterceptor(Contextcontext){mContext=context;}@OverridepublicResponseintercept(Chainchain)throwsIOEx

android - 如果 Retrofit 已经在内部使用 OkHttp,为什么开发人员将 OkHttp 设置为 Retrofit

我知道,Retrofit在内部使用OkHttp。但是,我可以看到一些开发人员提供了以下方法的应用returnnewRetrofit.Builder().baseUrl(BuildConfig.API_ENDPOINT).client(getClient())//wecanaddOkHttpClientclientthere那么,有人可以澄清为什么需要这样做吗?我听说这对测试很有帮助,因为我们可以在模拟HTTP请求期间应用自定义拦截器 最佳答案 Retrofit本身确实获得了OkHttp的实例,但不对OkHttpClient执行任何自

android - 使用改造和 rx java 的多个 api 请求

我是android的新手,我有一个场景,我想从多个api获取数据。假设api_a、api_b、api_c、api_d。这些api彼此独立,但我想在混合RecyclerView(水平和垂直)中显示来自这些api的数据。所以我想以这种方式进行这些api调用,以便我可以一次获取每个api数据,以便我可以在回收站View中显示。我已经在使用retrofit2但为此我不得不将它们一个接一个地链接起来,这非常冗长,我认为这不是一种可行的方法。我对RXJAVA知之甚少,但我一次只知道如何发出一个请求。请帮忙 最佳答案 至少有两种方法可以实现这一点

android - 是否可以使用 Retrofit 通过 Multipart 发送 String[]?

我正在开发一个应用程序,在该应用程序中,用户必须从列表中选择任意数量的国家,并且我必须通过多部分发送所选名称。我没有将任何文件与String[]一起上传,但是如果不是多部分就没有上传信息的途径,而且我对Web服务器的运行方式没有任何说法。我试图简单地将它作为数组、ArrayList和JsonArray发送:@Headers({"Connection:Keep-Alive",})@Multipart@PUT("/user/{id}")StringupdateUser(@Path("id")intuserId,@Part("user[countries]")String[]countrie

android - OkHttp SSLHandshakeException SSL 握手中止 SSL 库失败,协议(protocol)错误

04-2317:17:38.43421599-21956/D/NativeCrypto:ssl=0x0NativeCrypto_SSL_interrupt04-2317:17:38.43521599-21956/D/OkHttp:Android较低版本设备(4.1-4.4)出现SSL错误。以前在以下版本中运行良好:implementation'com.squareup.okhttp3:okhttp:3.9.1'implementation'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'implementation'com.squareu