gpt4 book ai didi

java - 如何使用 Retrofit 发出请求

转载 作者:行者123 更新时间:2023-12-02 01:23:35 25 4
gpt4 key购买 nike

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();
}
});


}`

请求发生了什么问题,我不知道请帮忙

最佳答案

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>

关于java - 如何使用 Retrofit 发出请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57289675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com