2017-07-09 3 views
0

私はユーザーログインのためにAndroidアプリケーションにretrofitを実装しています。入力タイプはJsonです。 Retrofit経由でPOSTリクエストを送信しようとするたびに、500の内部サーバーエラーが発生します。内部サーバーエラーステータスを返す改造500

ApiInterface apiInterface=AppController.GetRetrofitObject().create(ApiInterface.class); 
     // prepare call in Retrofit 2.0 
     try { 
      JSONObject paramObject = new JSONObject(); 
      try { 
       paramObject.put(ApiName.USERNAME, username); 
       paramObject.put(ApiName.PASSWORD, password); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 

      Log.d(TAG,paramObject.toString()); 
      Call<Login> call = apiInterface.getLoginDetails(paramObject.toString()); 
      call.enqueue(new Callback<Login>() { 
       @Override 
       public void onResponse(@NonNull Call<Login> call, @NonNull Response<Login> response) { 
        String message = response.message(); 
        int status = response.code(); 

        Log.d(TAG, String.valueOf(status)); 
        Intent homeIntent = new Intent(getApplicationContext(), MainActivity.class); 
        startActivity(homeIntent); 
       } 

       @Override 
       public void onFailure(Call<Login> call, Throwable t) { 

       } 
      }); 
     }catch (Exception e){ 
      e.printStackTrace(); 
     } 

たびに、私は500、ステータスを取得していますが、私はPOSTMAN.Myインタフェースクラスの応答を取得していますが

public interface ApiInterface { 

@POST(ApiName.LOGIN) 
Call<Login> getLoginDetails(@Body String body); 
} 

Postman screen shot

+0

プリントURLを –

答えて

0

変更String bodyがJava POJOになることです。 ....... User

@POST(ApiName.LOGIN) 
Call<Login> getLoginDetails(@Body User body); 
} 

class User { 

private String username; 
private String password; 

public User() {} 

public User(String username, String password) { 
    this.username = username; 
    this.password = password; 
} 

// setter + getter// 

} 

その後、呼び出し:例えばAPI呼び出し機能で

.... 

User user = new User(username, password); 
Call<Login> call = apiInterface.getLoginDetails(user); 

.... 
関連する問題