如何发送带有包含图像文件和其他属性的json主体的Retrofit2.0发布请求 我有一个对象模型,用键和图像序列化字符串来保存图像路径如下Android如何发送包含图像文件和其他属性的json主体的Retrofit2.0发布请求
public class SeekerProfileModel implements Serializable
{
@SerializedName("fname")
private String fname=null;
@SerializedName("lname")
private String lname=null;
@SerializedName("paswd")
private String password=null;
@SerializedName("promoter")
private String promoter=null;
@SerializedName("dob")
private String dob=null;
@SerializedName("gender")
private String gender=null;
@SerializedName("ph")
private String phone=null;
@SerializedName("email")
private String email=null;
@SerializedName("weight")
private String weight=null;
@SerializedName("height")
private String height=null;
@SerializedName("qualification")
private String qualification=null;
@SerializedName("color")
private String color=null;
@SerializedName("lang_known")
private String languages=null;
@SerializedName("experience")
private String experience=null;
@SerializedName("exp_type")
private String experienceType=null;
@SerializedName("dres_code")
private String dressCode=null;
@SerializedName("vehicle_mode")
private String vehicleMode=null;
@SerializedName("id_proof")
private String idproof=null;
@SerializedName("size")
private String size=null;
@SerializedName("photo1")
private String photo1=null;
@SerializedName("photo2")
private String photo2=null;
@SerializedName("photo3")
private String photo3=null;
@SerializedName("address")
private String address=null;
@SerializedName("landmark")
private String landmark=null;
@SerializedName("location")
private String location=null;
@SerializedName("city")
private String city=null;
@SerializedName("state")
private String state=null;
@SerializedName("contry")
private String contry=null;
@SerializedName("pincode")
private String pincode=null;
@SerializedName("bank_name")
private String bankName=null;
@SerializedName("ac_name")
private String accountName=null;
@SerializedName("ac_number")
private String accontNumber=null;
@SerializedName("ifsc")
private String Ifsc=null;
@SerializedName("br_name")
private String branchName=null;
}
我的接口如下
@Multipart
@POST("empowerapp/seekerreg.php")
Call<ResponseModel> registerSeeker(
@Body SeekerProfileModel profileModel);
和我的方法调用是如下面
public void registerSeeker(SeekerProfileModel profileModel) {
System.out.println("###exp" + s_exp.getText().toString());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Allconstants.MAIN_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitInterface service = retrofit.create(RetrofitInterface.class);
Call<ResponseModel> call = service.registerSeeker(profileModel);
call.enqueue(new Callback<ResponseModel>() {
@Override
public void onResponse(Response<ResponseModel> response, Retrofit retrofit) {
System.out.println("###coming" + response.body().getStatus());
pd.dismiss();
if (response.body().getStatus().equalsIgnoreCase("Success"))
{
pd.dismiss();
loginSession.createLoginSession(Allconstants.SEEKER,Allconstants.S_REG_ACTIVITY,response.body().getName(), response.body().getId());
Toast.makeText(Registration.this,"successfully registered",Toast.LENGTH_LONG).show();
System.out.println("###coming"+response.body().toString());
}else{
pd.dismiss();
Toast.makeText(Registration.this,"oops!!!something went wrong..try again",Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Throwable t) {
pd.dismiss();
Toast.makeText(Registration.this, t.getStackTrace().toString(), Toast.LENGTH_LONG).show();
System.out.println("###error1" + t.getMessage());
System.out.println("###stack trace: ");
t.printStackTrace();
}
});
}
我只想知道如何使用post对象请求发送图像,我在接口中使用@Body ...我应该在pojo类中使用多部分,还是我该如何做...请帮助我出
任何帮助,将不胜感激
不要我需要发送它在多部分编码?在将图像转换为位图后,我到底需要做些什么?我是否应该像使用retrofit @body一样以同样的方式发送它? –
......你制作了SeekerProfileModel的另一个属性并将其分配给它。然后发送对象...其余的工作应该由服务器完成。 – sadat
意味着不需要多部分的东西? –