【问题标题】:How to make a request by using Retrofit如何使用 Retrofit 发出请求
【发布时间】:2019-12-08 21:49:10
【问题描述】:

This is actual image of POST request[使用Android Retrofit上传图片,如何使用retrofit进行Multipart请求][2]

我正在使用 Retrofit 发送多个图像文件以及字符串数据,但在服务器端字符串数据丢失

我的保存注册 API /*Save register*/ @Multipart @POST("Events/SaveRegistration") Call<ModelRegisterMember> saveRegister( @Part List<MultipartBody.Part> files, @Query("data") String memberData ); // body of request private void uploadMemberInfo(List parts, ModelMakeMemberRegister allMembers) {

    ProgressDialog progressDialog = new ProgressDialog(mContext);
    progressDialog.setMessage("Please Wait...");
    progressDialog.setCancelable(false);
    progressDialog.show();


    ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
    Call<ModelRegisterMember> call = apiInterface.saveRegister(parts, new Gson().toJson(allMembers));


    Log.e("Req", call.request().toString());
    Log.e("Body", call.request().body().toString());
    Log.e("Body", call.request().headers().toString());
    Log.e("json", new Gson().toJson(allMembers));
    call.enqueue(new Callback<ModelRegisterMember>() {
        @Override
        public void onResponse(Call<ModelRegisterMember> call, Response<ModelRegisterMember> response) {
            progressDialog.dismiss();
            MyUtils.showToast(mContext, response.body().getMessage());
        }
        @Override
        public void onFailure(Call<ModelRegisterMember> call, Throwable t) {
            Log.e("err", t.toString());
            progressDialog.dismiss();
        }
    });


}`

我不知道的请求出了什么问题,请帮忙

【问题讨论】:

    标签: java android retrofit multipartform-data


    【解决方案1】:
    fun uploadFile(@Url url:String, @Part("AppGuid") guid:RequestBody,
                  @Part("UserGuid") uuid:RequestBody? = null,
                  @Part("DeviceToken") token:RequestBody,
                  @Part("UserAppGuid") uAppGuid:RequestBody,
                  @Part("FileName") fileName:RequestBody,
                  @Part("FileType") fileType:RequestBody, @Part file: MultipartBody.Part): Call<JsonElement>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 2017-06-17
      • 2017-02-25
      • 2020-10-08
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      相关资源
      最近更新 更多