错误:
无法访问没有内容类型“application/x-www-form-urlencoded”的请求的正文字段
我已尽我所能,但由于此错误,我仍然无法发出 PUT HTTP 请求。
我也试过这个:
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
它仍然无法正常工作。
这是代码:
RaisedButton(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
color: Colors.green,
child: Text(
"Submit and Validate",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
onPressed: () async {
// widget.stockoid
var jsonbody = {
"oid": mainStockid,
"modifiedBy": userData['UserName'],
"modifiedOn": DateTime.now().toString(),
"submitted": true,
"submittedOn": DateTime.now().toString(),
"submittedBy": userData['UserName'].toString(),
};
for (Products i in selectedProducts) {
print('${i.oid.toString()} itemid');
//i.oid.toString(),
var stockupdate = {
"oid": i.oid,
"unitInStock": i.itemqty,
"modifiedBy": userData['UserName'].toString(),
"modifiedOn": DateTime.now().toString(),
};
//But I could print this data on the console
print(
'${i.oid}, ${i.itemqty.toString()},${userData['UserName']},
${DateTime.now().toString()} ploo');
await http
.put(
"http://api.ergagro.com:112/StockItem/UpdateStockItem",
headers: {
'Content-Type': 'application/json'
},
body: jsonEncode(stockupdate))
//The value returns 404 witht that error
.then((value) {
print(value.statusCode);
});
}
await http
.put(
'http://api.ergagro.com:112/SubmitDailyStockTaking',
headers: {
'Content-Type': 'application/json'
},
body: jsonEncode(jsonbody))
.then((value) {
print('${value.statusCode} subb');
});
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) =>
StartScanPage(widget.dcOid)));
//Send to API
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(300),
),
),