Вот что я пробовал:
Мой интерфейс
Код: Выделить всё
public interface APIHandler {
@Headers("Content-Type: application/x-www-form-urlencoded")
@FormUrlEncoded
@POST(URL)
Call getdata(@Field("jdata") String jdata);
}
Код: Выделить всё
public void load() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("BASE_URL")
.addConverterFactory(GsonConverterFactory.create())
.build();
// prepare call in Retrofit 2.0
APIHandler iAPI = retrofit.create(APIHandler.class);
String requestBody = "{\"id\":\"value\",\"id1\":\"value2\"}"
Call call = iAPI.getData(requestBody);
call.enqueue(new Callback() {
@Override
public void onResponse(Call c, Response response) {
if (response.isSuccess()) {
ResponseBody result = response.body();
String gs = new Gson().toJson(result);
Log.d("MainActivity", "response = " + gs + " status: " + statusCode);
} else {
Log.w("myApp", "Failed");
}
}
@Override
public void onFailure(Call c, Throwable t) {
}
});
}
Подробнее здесь: https://stackoverflow.com/questions/358 ... tring-body
Мобильная версия