提问人:Bigbear 提问时间:11/9/2023 最后编辑:Brian Tompsett - 汤莱恩Bigbear 更新时间:11/10/2023 访问量:26
Vue3 POST 将 JSON 转 .Net API
Vue3 POSTing JSON to .Net API
问:
当我尝试调用我的 API POSTing 数据时,我不断收到 400 个错误请求。 POST http://localhost:5081/Purchasing/TestCall/190200 400(错误的请求)
这是我的 Vue Call
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(lstOrders.value),
};
fetch("http://localhost:5081/Purchasing/TestCall/"+ workOrder.value, requestOptions)
我从这些调用创建的数组中的对象
//return Ok(lstPDFs.OrderBy(x => x.FileName));
return Ok(JsonSerializer.Serialize(lstPDFs.OrderBy(x => x.FileName)));
它看起来像这个 JSON 数据:
在开发工具中,它是console.log(myReturnedList)
[[Target]]:Array(10)
0:{AutoID: 0, FileName: '4700.9359', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
1:{AutoID: 0, FileName: 'I_101', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
2:{AutoID: 0, FileName: 'I_102', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
3:{AutoID: 0, FileName: 'I_103four', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
4:{AutoID: 0, FileName: 'I_104', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
5:{AutoID: 0, FileName: 'I_105GC', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
6:{AutoID: 0, FileName: 'I_201', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
7:{AutoID: 0, FileName: 'I_202MMEvolution', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
8:{AutoID: 0, FileName: 'MMEvo', FilePath: 'C:\\temp\\batchprint\\engserv\\190200\\Installation', FileSize: 0, CreatedDate: '0001-01-01T00:00:00', …}
所以我的数据是 JSON,它和一个对象列表,这是我的下一个 API 调用所期望的。 这是我的 API 请求方法
[EnableCors]
[HttpPost("TestCall/{projectNumber}")]
public IActionResult TestCall(string projectNumber, [FromBody] List<PDFFile> pdfs)
{
_logger.LogInformation("TEST");
return Ok();
}
答: 暂无答案
评论
PDFFile