所以我正在尝试从 Java 中发布表单。到我的.net core webapi。直到我添加了发送内部对象数组的要求之前,表单发布工作得很好。我想相信,当我发表文章时,我的 .net 无法理解它接收到的有效负载。所以下面的java代码将值发送到.net core。在假设收集(绑定)来自java代码的请求的模型之后也被粘贴
//此方法将把值发布到.net
public <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 控制器。
守着星空守着你
相关分类