我正在尝试通过翻新添加JSON请求,因为服务器需要JSON请求才能提取数据。
这是我要添加的请求:
{"VALID_FROM":"2018-01-01","VALID_TO":"2019-03-15"}
如果邮递员没有有效载荷,我会收到此消息
INCORRECT_PAYLOAD_DATA ::::::处理消息有效负载时出错 元素“ VALID_FROM”丢失
这是我的API接口 SapRestApi.Java
public interface SapRestApi {
@Headers("Accept: application/json")
@GET("/get_users")
Call<UserList> getUserList();
}
这是我的用户类,在其中找到了获取器和设置器 User.Java
public class User implements POJO {
@SerializedName("USERNAME")
private String USERNAME;
@SerializedName("VALID_FROM")
private String VALID_FROM;
@SerializedName("VALID_TO")
private String VALID_TO;
public String getUserName() {
return USERNAME;
}
public String getValidFrom() {
return VALID_FROM;
}
public String getValidTo() {
return VALID_TO;
}
public void setUserName(String USERNAME) {
this.USERNAME = USERNAME;
}
public void setValidFrom(String VALID_FROM) {
this.VALID_FROM = VALID_FROM;
}
public void setValidTo(String VALID_TO) {
this.VALID_TO = VALID_TO;
}
}
private String USERNAME;
这是我所谓的getUserList()
public UserList getUserList() {
UserList userAccounts = null;
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient
.addInterceptor(new BasicAuthInterceptor(userName, password))
.build())
.build();
SapRestApi userAPI = retrofit.create(SapRestApi.class);
Call<UserList> callSync = userAPI.getUserList();
try {
Response<UserList> response = callSync.execute();
System.out.println("Creating Response after Call Sync Execute Method ");
System.out.println(response.toString());
userAccounts = response.body();
} catch (IOException e) {
e.printStackTrace();
}
return userAccounts;
}
每当没有有效负载时,我都会收到错误500。 谢谢!