2016-04-23 61 views
-1

我想打後一個服務器,並得到響應主體,以顯示它 但仍然總是得到空字符串得到空應答體retrofit2

這是我的接口類

@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) { 

      } 
     }); 

回答

2

其依賴於烏爾服務器哪些數據接受,如果編碼然後調用像它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

相關問題