簡體   English   中英

無法讀取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:提取調用中缺少必需的請求正文

[英]Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing From a Fetch Call

我想獲取包含json和文件的JSONArray到我的服務器,但是出現此錯誤

無法讀取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:缺少必需的請求正文:public java.lang.String controllers.IngestController.ingestDataFile(org.json.JSONArray)

我的提取呼叫包括

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: 'headerIngestion' }, { body: 'this.state.csv' } ]})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM