【问题标题】:Retrofit2 pass array in body正文中的 Retrofit2 传递数组
【发布时间】:2019-09-03 08:40:02
【问题描述】:

如何在retrofit2 中执行此发布请求?

curl --location --request POST "http://localhost/projectjcms/api/search-result" \
  --header "accessToken: eyJ0eOiJK 3ZN_ud117ZPLSQMC0ry-tGUfOmLvgsLqRQIA" \
  --header "lang: 1" \
  --header "Content-Type: text/plain" \
  --form "property_type[0]=1" \
  --form "property_type[1]=2" \
  --form "bedroom_type[0]=1" \
  --form "bedroom_type[1]=5" \
  --form "bedroom_type[2]=3"

RequestBody unitDetailsRequestBody = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("property_id[0]", "3") //.addFormDataPart("property_id[1]", "2") .build();

   // @FormUrlEncoded
    @POST("api/search-result")
    Call<Frame> getSearchResult(@Header("accessToken") String accessToken,
                                @Header("lang") int language,
                                @Header("Content-Type") String contentType,
                                @Body String body);

【问题讨论】:

  • 12
  • 没有解决我的问题

标签: android retrofit retrofit2


【解决方案1】:

您可以参考下面的代码来调用API。

@FormUrlEncoded
@POST("api/search-result")
Call<Frame>  getSearchResult(@Field("property_type[]") String[] propertyType,
                     @Field("bedroom_type[]") String[] bedroomType);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 2018-11-25
    • 2017-05-23
    • 2021-10-16
    • 1970-01-01
    • 2014-04-10
    • 2021-09-22
    相关资源
    最近更新 更多