Javascript 无法读取HTTP消息:org.springframework.HTTP.converter.httpMessageNodeTableException:提取调用中缺少必需的请求正文
我想获取一个包含json和文件的JSONArray到我的服务器,但是我得到了这个错误 无法读取HTTP消息: org.springframework.http.converter.httpMessageNodeTableException: 缺少必需的请求正文:public java.lang.String controllers.IngestController.ingestDataFile(org.json.JSONArray) 我的取回呼叫包括Javascript 无法读取HTTP消息:org.springframework.HTTP.converter.httpMessageNodeTableException:提取调用中缺少必需的请求正文,javascript,java,spring,rest,Javascript,Java,Spring,Rest,我想获取一个包含json和文件的JSONArray到我的服务器,但是我得到了这个错误 无法读取HTTP消息: org.springframework.http.converter.httpMessageNodeTableException: 缺少必需的请求正文:public java.lang.String controllers.IngestController.ingestDataFile(org.json.JSONArray) 我的取回呼叫包括 var data = [
var data = [
{
"header": headerIngestion
},
{
"body": this.state.csv
}
];
fetch('http://localhost:8080/ingest', {
method: 'POST',
body: data
})
.then...
headerIngestion
只是一个常规的JSON,csv
是一个csv文件上传
我的服务器方法是
@PostMapping(INGEST_URL)
public String ingestDataFile(@RequestBody JSONArray jsonArr) {
System.out.println(jsonArr.toString());
return "temporary return";
}
您的json格式不正确,因此无法转换为JSONArray。试试这个。我没有亲自运行它来测试它,所以可能没有完美的json框架,但你明白了
body:JSON.stringify({[{header:'headeringesting'},{body:'this.state.csv'}]})
我以为JSONArray是以[而不是{?