Я пытаюсь отправить многочастный почтовый запрос с помощью Retrofit, но я не могу это сделать. Ниже приведены данные моего запроса на отправку, которые мне нужно отправить на сервер, используя multipart
.
{
"name":"Akhil",
"email":"akhil.garg@gmail.com",
"password":"123456",
"phoneNumber":"9988928289",
"countryCode":"IN",
"pincode":"wddw33",
"latitude":321332.434,
"longitude":232132121.44,
"address":{
"addressLine1":"efefewf",
"addressLine2":"fefewffew"
}
}
. Я делаю так:
public interface RegisterInterface {
@Multipart
@POST("register")
Call<Root> signUp(
@Part("name") RequestBody name,
@Part("email") RequestBody email,
@Part("password") RequestBody password,
@Part("phoneNumber") RequestBody phoneNumber,
@Part("countryCode") RequestBody countryCode,
@Part("pincode") RequestBody pincode,
@Part("latitude") RequestBody latitude,
@Part("longitude") RequestBody longitude,
@Part("address") RequestBody address
);
}
private void registerUser(String address){
HashMap<String,String> address1= new HashMap();
address1.put("addressLine1","B-184");
address1.put("addressLine2","New Delhi");
RequestBody uEmail = RequestBody.create(MediaType.parse("email"), email.getValue());
RequestBody uname = RequestBody.create(MediaType.parse("name"), name.getValue());
RequestBody upassword = RequestBody.create(MediaType.parse("password"), password.getValue());
RequestBody phoneNumber = RequestBody.create(MediaType.parse("phoneNumber"), phoneNo.getValue());
RequestBody countryCode = RequestBody.create(MediaType.parse("countryCode"), "IN");
RequestBody pincode = RequestBody.create(MediaType.parse("pincode"), "110092");
RequestBody latitude = RequestBody.create(MediaType.parse("latitude"), 24.0987+"");
RequestBody longitude = RequestBody.create(MediaType.parse("longitude"), 43.09567+"");
RequestBody uaddress = RequestBody.create(MediaType.parse("address"), data1);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ApiUrl.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RegisterInterface vInterface = retrofit.create(RegisterInterface.class);
RegisterationModel imageDataSet = new RegisterationModel(name.getValue(),phoneNo.getValue(),email.getValue(),password.getValue(),22.0987,43.09876,data1,"IN","110092");
Call<Root> serverCom = vInterface.signUp(uname,uEmail,upassword,phoneNumber,countryCode,pincode,latitude,longitude,uaddress);
serverCom.enqueue(new Callback<Root>() {
@Override
public void onResponse(Call<Root> call, Response<Root> response) {
//Data result = response.body().getData();
Log.d("Result",response.body()+"");
if (response!=null) {
Toast.makeText(context, "File Successfully Uploaded", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Root> call, Throwable t) {
}
});
}