새로운 기능 Retrofit Library에 대한 새로운 내용과 게시 방법으로 개체를 보내는 이유가 무엇인지 더 알고 싶습니다.Retrofit 2 POST를 사용하여 개체를 보내십시오.
여기에 몇 가지 코드가 있습니다.
나의 등급 :
public class ExampleClass implements Serializable {
@SerializedName("id")
int id;
@SerializedName("name")
String name;
public ExampleClass(int id, String name) {
this.id = id;
this.name= name;
}
}
내 인터페이스 : 개조와
public interface ApiInterface {
@Headers("Content-Type: application/json")
@POST("getclass/")
Call<ExampleClass> getExampleClass(@Body ExampleClass exampleClass);
}
내 전화 :
......
ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<ExampleClass> call = apiService.getExampleClass(exampleClass);
call.enqueue(new Callback<ExampleClass>() {
@Override
public void onResponse(Call<ExampleClass> call, Response<ExampleClass> response) {
int statusCode = response.code();
Log.i(TAG, "Status Code: " + statusCode);
}
@Override
public void onFailure(Call<ExampleClass> call, Throwable t) {
Log.i(TAG, "Error: " + t.toString());
}
});
그러나 모든 시간은 나에게 상태 코드를 반환 (500)
누군가 날 이드에게 줄 수 있니? retrofit으로 객체를 보내려면?
@FormUrlEncoded
@Headers("Content-Type: application/json")
@POST("getclass/")
Call<ExampleClass> getExampleClass(@Field("id") int id, @Field("name") String name);
을하지만 난 당신의 방법은 가장 쉽고 올바른 생각 :
을 위해 잘 작동 또한 ADB 로그를 추가하시기 바랍니다 스택 추적 –
를 추가하십시오 검토 할 수 있습니다. –
개조 공사 인스턴스에 Gson 또는 Jackson 변환기를 추가 했습니까? – nexus5x