我正在尝试通过android中的retrofit2通过HTTP将JSON消息发送到运行其余api的django服务器。
使用改造接口和调用:
@POST("getDates/")
Call<Event> newEvent(@Body Event event);
@PUT("getDates/{id}/")
Call<Event> updateEvent(@Path("id") int id, @Body Event event);
以及
public void postNewEvent(Event event) {
Call<Event> call = service.newEvent(event);
call.enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
Log.i("REST", "POST was sucessful: " + response.isSuccessful());
Log.i("REST", "response body: " + response.body().toString());
Log.i("REST", "response message: " + response.message());
Log.i("REST", "response code: " + response.code());
Log.i("REST", "response code: " + response.errorBody());
}
@Override
public void onFailure(Call<Event> call, Throwable t) {
Log.e("REST", t.getMessage());
Log.e("REST", call.toString());
}
});
}
public boolean updateEvent(Event event) {
Call<Event> call = service.updateEvent(event.getId(), event);
call.enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
success = response.isSuccessful();
}
@Override
public void onFailure(Call<Event> call, Throwable t) {
Log.e("REST", t.getMessage());
}
});
}
但是,我通过界面发送到服务器的每条消息只能得到以下答复:OK和code:200。 我尝试过通过api手动发送调用,并且效果很好。 这段代码过去也对我有用,但是现在它停止了。 我添加了Nginx服务器和Gunicorn而不是UWSGI,但我无法想象它们会阻止应用程序。
有人知道可能出什么问题吗?我只是想不通!