Я пытаюсь отправить необработанные данные в запросе POST, но ключ nameValuePairs объединяется с моим JSON.
Вот мой метод запроса: -
@Headers( "Content-Type: application/json; charset=utf-8")
@POST("mpapi/seller/sellerprofilepost")
Call<ResponseBody>
updateProfile(@Header("Authorization") String token,
@Body JSONObject body);
Я отправляю это: -
{
"firstname": "test1ff"
}
но в бэкэнде они получают: -
{
"nameValuePairs":
{
"firstname":"test1ff"
}
}
Метод вызова API: -
private void updateProfile() {
try {
showLoader();
JSONObject obj=new JSONObject();
obj.put("firstname",first_name.getText().toString().trim());
call = api.updateProfile("Bearer k8yu1q0k790lw5y4ta49alfbtsxoxs1w",obj);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
if (response.isSuccessful()) {
JSONObject obj = new JSONObject(response.body().string());
dialog = Func.OneButtonDialog(mContext, obj.getString("message"), ProfileScreen.this);
} else {
JSONObject obj = new JSONObject(response.errorBody().string());
dialog = Func.OneButtonDialog(mContext, obj.getString("message"), ProfileScreen.this);
}
} catch (Exception e) {
dialog = Func.OneButtonDialog(mContext, getResources().getString(R.string.ERROR_MSG), ProfileScreen.this);
e.printStackTrace();
}
hideLoader();
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
dialog = Func.OneButtonDialog(mContext, getResources().getString(R.string.ERROR_MSG), ProfileScreen.this);
hideLoader();
}
});
} catch (Exception e) {
dialog = Func.OneButtonDialog(mContext, getResources().getString(R.string.ERROR_MSG), this);
hideLoader();
e.printStackTrace();
}
}
Метод вызова дооснащения: - вот мое дооснащениевызов метода, где я устанавливаю базовый URL, заголовки и т. д.
public Retrofit retrofitCall() {
String baseUrl = Constants.baseURL;
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.sslSocketFactory(getSSLSocketFactory())
.retryOnConnectionFailure(true)
.addInterceptor(new AddHeaderInterceptor())
.readTimeout(40, TimeUnit.SECONDS)
.connectTimeout(40, TimeUnit.SECONDS)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit;
}