我正在尝试调试此问题" Http 500内部访问错误"为此,代码如下所示:
private void submitOrder() {
List<String> itemIds = new ArrayList<>();
List<Integer> itemQuantity = new ArrayList<>();
for (FoodTruckItem foodTruckItem : foodTruckItemList) {
itemIds.add(foodTruckItem.getItemId());
itemQuantity.add(foodTruckItem.getItemQuantityOrdered());
}
if (InternetConnection.checkConnection(this)) {
Observable<GenericResponse> results = RetroClient.getApiService()
.submitOrder("******", "", total,
"anywhere", "", "*****", itemIds, itemQuantity,
foodtruckInfo.getFoodTruckId());
results.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<GenericResponse>() {
@Override
public void onCompleted() {
unsubscribe();
}
@Override
public void onError(Throwable e) {
Toast.makeText(MyCartActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onNext(GenericResponse response) {
showOrderCompleteFragment();
}
});
} else {
}
}
在这里,当我发送带有2个项目的webservice时这会正常工作,但对于一个项目,它会产生500个内部服务器错误。但是对于每个案例邮递员成功创建订单
邮递员的回复如下所示:
答案 0 :(得分:0)
我认为您需要使用Map
itemIds
和itemQuantity
代替List<String>/List<Integer>
,如下所示:
在RetroClient.getApiService().submitOrder()
@FieldMap Map<String, String> itemIdsMap
@FieldMap Map<String, String> itemQuantityMap
现在传递itemIds
和itemQuantity
值,如下所示:
Map<String, String> itemIdsMap = new HashMap<>();
Map<String, String> itemQuantityMap = new HashMap<>();
String itemIds = "item_id[%d]";
String itemQuantity = "item_quantity[%d]";
for (int i = 0; i < foodTruckItemList.size(); i++) {
itemIdsMap.put(String.format(itemIds, i), foodTruckItemList.get(i).getItemId());
itemQuantityMap.put(String.format(itemQuantity, i), foodTruckItemList.get(i).getItemQuantityOrdered());
}