所以我正在嘗試從 Java 中發布表單。到我的.net core webapi。直到我添加了發送內部對象數組的要求之前,表單發布工作得很好。我想相信,當我發表文章時,我的 .net 無法理解它接收到的有效負載。所以下面的java代碼將值發送到.net core。在假設收集(綁定)來自java代碼的請求的模型之后也被粘貼//此方法將把值發布到.netpublic <T> T Handlepost(File inFile,Productmodel model,final Class<T> objectClass) { FileInputStream fis = null; try { StringBody name = new StringBody(model.getName()); StringBody barcode = new StringBody(model.getBarcode()); StringBody quantity = new StringBody(model.getStockQuantity()+""); StringBody unitcost = new StringBody(model.getUnitCost()+""); StringBody discountamt = new StringBody(model.getDiscountamt()+""); StringBody describe = new StringBody(model.getDescription()); StringBody companyid = new StringBody(model.getCompanyID()+""); StringBody unitid = new StringBody(model.getUnit().getID()); StringBody inventorycatid = new StringBody(model.getProductposcategory().getID()); String hascolors = ""; if(model.getHascolortypes()){ hascolors = "yes"; } else hascolors = "no"; StringBody hascolortypes = new StringBody(hascolors); if(inFile != null){ fis = new FileInputStream(inFile); } DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams()); String Posturl = urlobject.Createproducturl(); // server back-end URL HttpPost httppost = new HttpPost(Posturl); //"http://localhost:56175/api/product/create" MultipartEntity entity = new MultipartEntity();//這是內部對象的數組。我用它來收集用戶的多個選擇。因此,我必須將有效負載中的對象數組發送到我的 .net 控制器。
1 回答

守著星空守著你
TA貢獻1799條經驗 獲得超8個贊
代碼是正確的。有一個空指針字符串。字符串描述不是從 GUI 界面傳遞的。這導致了錯誤。
Costpersizes[] 值也更改為 Costpersizes[k]。需要傳遞索引,以便 api 能夠區分數組中的行。
添加回答
舉報
0/150
提交
取消