【发布时间】:2021-04-03 22:06:20
【问题描述】:
我对 Retrofit 调用有疑问。我曾调用在服务器上发布数据,调用返回 200 响应,这意味着调用成功,但它没有将任何数据保存到数据库并在服务器堆栈跟踪中返回消息“请求为空”。没有得到响应数据。
接口调用
@Headers({"org-id: vuk"})
@POST("/dmp/user/loginwithotp")
Call<ResponseAPI> signInWithOTP(@Body RequestBody jsonObject);
改造电话
OkHttpClient client = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))
.addInterceptor(loggingInterceptor)
.addNetworkInterceptor(new CacheInterceptor(mContext))
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl )
.addConverterFactory(GsonConverterFactory.create(new Gson()))
.client(client)
.build();
return retrofit;
}
public static VuAPIServices geVuAPIServices() {
VuAPIServices vuAPIServices = getRetrofit().create(VuAPIServices.class);
return vuAPIServices;
}
活动中发送调用请求和响应调用的代码
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("mobileNumber", mobileNumber);
RequestBody body = RequestBody.create(json.toString(), MediaType.parse("application/json;charset=UTF-8"));
Call<ResponseAPI> responseAPICall = ApiClient.geVuAPIServices().signInWithOTP(body);
responseAPICall.enqueue(new Callback<ResponseAPI>() {
@Override
public void onResponse(Call<ResponseAPI> call, retrofit2.Response<ResponseAPI> response) {
if(!response.isSuccessful()) {
Log.e("TAG", "response: "+new Gson().toJson(response.body()) );
}
}
@Override
public void onFailure(Call<ResponseAPI> call, Throwable t) {
Log.e("TAG", "onFailure: "+t.toString() );
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
响应 POJO
@SerializedName("flag")
private int flag;
@SerializedName("message")
private String message;
@SerializedName("status")
private Boolean status;
@SerializedName("otp")
private String otp;
@SerializedName("locked")
private Boolean locked;
@SerializedName("firstTimeLogin")
private Boolean firstTimeLogin;
@SerializedName("firstLogin")
private Boolean firstLogin;
Getter and Setters...
邮递员图片
我应该对我的代码进行哪些更改?我欢迎每一个提示。我得到的状态是 200 但服务器端的请求为空。
已更新响应结果
E/TAG: response: {"firstLogin":false,"firstTimeLogin":false,"flag":0,"fromInternalApp":false,"locked":false,"mobileNumber":"4455332266","noToken":false,"status":false}
【问题讨论】:
-
postman发送请求时是否保存数据?
-
是的,它会在邮递员发送请求时保存
-
谁能帮我解决这个问题?
标签: java android json api postman