【问题标题】:Send ArrayList<String> with Retrofit to server将带有改造的 ArrayList<String> 发送到服务器
【发布时间】:2020-07-07 20:04:14
【问题描述】:

我是改装新手,我正在尝试将字符串类型的 arraylist 发送到服务器,

我见过几个关于堆栈溢出的解决方案。

我在方法方面遇到问题。我不知道如何在方法中发送数组列表。

我尝试了两种不同的方法

方法一:

这是我的界面:

@Multipart
@PUT("profile")
Call<ProfileSetupResponse3> vendorProfile3(
        @Header("access-token") String token,
        @Part("name") RequestBody name,
        @Part("step") RequestBody step,
        @Part("description") RequestBody description,
        @Part("highlights") RequestBody highlights,
        @Part("minQuantity") RequestBody minQuantity,
        @Part("available") RequestBody available,
        @Part("warrantyDetail") RequestBody warrantyDetail,
        @Part("warrentyPeriod") RequestBody warrentyPeriod,
        **@Query("categories[]") ArrayList<RequestBody> categories**
    
);


ArrayList<RequestBody> cat = new ArrayList<>();
            cat.add(createFromString("Paintsas"));
Call<ProfileSetupResponse3> call = RetrofitClient
                    .getInstance()
                    .getApi()
                    .vendorProfile3(....,cat)

方法二:

@Query("categories[]") ArrayList<String> categories

ArrayList<String> categories = new ArrayList<>();
categories.add("APskaoj");
            categories.add("APskaoj");
            categories.add("APskaoj");
Call<ProfileSetupResponse3> call = RetrofitClient
                    .getInstance()
                    .getApi()
                    .vendorProfile3(....,categories)

我仍然无法将我的数组列表发送到服务器。

我们将不胜感激。

【问题讨论】:

    标签: android arraylist retrofit retrofit2


    【解决方案1】:

    抱歉,我无法发表评论...

    Query 参数附加到 URL 例如:

     @GET("/friends")
    
     Call<ResponseBody> friends(@Query("page") int page);
     
     Calling with foo.friends(1) yields /friends?page=1.
    

    这来自 Retrofit2 的文档:https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Query.html

    没有看到 API 规范。我会说将@Query 更改为@Body

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多