我想在服务器上发帖子,并让响应主体显示它 但仍然总是得到空字符串
这是我的界面类
@POST("peserta/cek")
Call<CekPeserta> cekPeserta(@Body String kode_tiket);
class Factory {
private static PesertaAPI service;
public static PesertaAPI getInstance(){
if (service == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(PesertaAPI.class);
return service;
}
else return service;
}
}
和mainClass
PesertaAPI.Factory.getInstance().cekPeserta("SDL8S3").enqueue(new Callback<CekPeserta>() {
@Override
public void onResponse(Call<CekPeserta> call, Response<CekPeserta> response) {
Log.i("post status","sukses");
Log.i("nama = ", String.valueOf(response.body().getName()));
}
@Override
public void onFailure(Call<CekPeserta> call, Throwable t) {
}
});
答案 0 :(得分:2)
它依赖于ur服务器接受哪些数据,如果它的FormUrl
编码然后调用...
@POST("peserta/cek")
@FormUrlEncoded
Call<CekPeserta> cekPeserta(@Body // your data );
如果它在JSON Form
中接受,则调用如..
@POST("peserta/cek")
@Headers("Content-Type: application/json")
Call<CekPeserta> cekPeserta(@Body // your data);
了解更多信息..和详细信息click-here