【发布时间】:2017-12-13 06:01:00
【问题描述】:
我正在我的 android 应用程序中实现用户登录的改造。输入类型为 Json。每次我尝试通过 Retrofit 发送 POST 请求时,都会出现 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 中得到响应。我的接口类是
public interface ApiInterface {
@POST(ApiName.LOGIN)
Call<Login> getLoginDetails(@Body String body);
}
【问题讨论】:
-
在api调用函数中打印url
标签: android json http-post retrofit2