我对改装POST请求有疑问。我尝试发送带有少量字段的Object,以及里面的数组。我读到最好的解决方案是用@Body来做。但是服务器返回错误 - 正在发送null项目。这是我的帖子方法:
@POST("/api/mobile/{language}/{apiVersion}/beacons/try-save-settings")
void trySaveBeaconParams(
@Body EonBeaconModel model,
Callback<BasicResponse<Object>> callback);
这是我的EonBeaconModel.class:
@Table(name = "eonBeacon")
public class EonBeaconModel extends Model {
@Column(unique = true, onUniqueConflict = Column.ConflictAction.REPLACE, index = true)
public long beacon_id;
@Column
public long bridge_id;
@Column
public long mesh_id;
@Column
public String name;
@Column
public String location;
@Column
public String mac_address;
@Column
public String firmware;
@Column
public String pcb_revision;
@Column
public int battery_level;
@Column
public String password;
@Column
public String assigned_bridge_id;
@Column(name="Eeid")
public Eeid eeid;
@Column(name="Etlm")
public Etlm etlm;
@Column
public Euid euid;
@Column(name="Eurl")
public Eurl eurl;
@Column(name="Ib")
public IbModel ibBeaconModel;
@Column
public String jsonIB;
@Column
public String jsonEeid;
@Column
public String jsonEtlm;
@Column
public String jsonEuid;
@Column
public String jsonEurl;
@Column
public boolean isBeacon;
@Column(name="sleep_modes")
public List<SleepMode> sleep_modes;
@Column
public String jsonSleep;
这就是我创建回调的方式:
@Subscribe
public void validateNewBeaconData(ValidateNewBeaconDataCommand command) {
Callback<BasicResponse<Object>> callback = new Callback<BasicResponse<Object>>() {
@Override
public void success(BasicResponse<Object> basicResponse, Response response) {
if (ResponseStatus.SUCCESS.statusCode == basicResponse.status) {
EventBus.post(new BeaconsSettingsValidatedEvent());
Log.e(TAG, "success: ");
}
else {
EventBus.post(new NetworkFailureEvent(ResponseStatus.getByStatus(basicResponse.status), basicResponse.status_msg));
Log.e(TAG, "failure validate: " );
}
}
@Override
public void failure(RetrofitError error) {
EventBus.post(new NetworkFailureEvent(ResponseStatus.NETWORK_ERROR, messageString));
Log.e(TAG, "failure: " + error.getCause() );
}
};
Log.e(TAG, "validateNewBeaconData: " + command.model.eurl.interval );
service.trySaveBeaconParams(command.model
,
callback);
}
这是我的Command类:
public class ValidateNewBeaconDataCommand extends ApiCommand {
public EonBeaconModel model;
public ValidateNewBeaconDataCommand(EonBeaconModel model) {
this.model=model;
}
}
我已经在调试时检查了它,并且在调用Callback时命令isn&t; t null - 它包含来自EonBeaconModel对象的所有字段。唯一的问题是将其发送到服务器。有什么帮助吗?
POST应如下所示:
答案 0 :(得分:0)
尝试在POST Url的末尾添加斜杠,例如:
@POST("/api/mobile/{language}/{apiVersion}/beacons/try-save-settings/")