我们使用的是带有springboot的react js。我们已经从邮递员表单数据中编写了服务和检查。它在工作,但当我们使用react js时,它不工作。Rest端点命中,但未将有效负载数据加载到服务。对于React,我们使用const formData = new FormData()并附加所有需要的输入。React代码
const formData = new FormData();
formData.append("event", this.state.status);
formData.append("startDate", this.state.startDateTxt);
formData.append("sourceSystem", this.state.sourceSystem);
formData.append("endDate", this.state.endDateTxt);
formData.append("minPrice", this.state.minPrice);
formData.append("maxPrice", this.state.maxPrice);
httpRequest.open("POST", "http://localhost:8080/sa/searchData", true);
httpRequest.setRequestHeader("Content-Type","application/form-data");
httpRequest.onreadystatechange = () => {
console.log("httpRequest.readyState",
httpRequest.readyState);
if (httpRequest.readyState === XMLHttpRequest.DONE
&& httpRequest.status === 200) {
console.log("httpRequest.responseText ", httpRequest.responseText);
updateData(JSON.parse(httpRequest.responseText));
}
};
httpRequest.send(formData);弹簧靴
@PostMapping(value = "/sa/searchData")
public List<DataResponse> searchData(SearchCriteria searchCriteria) {
return saService.searchData(searchCriteria);
}发布于 2020-02-26 00:32:35
错误代码'408'表明问题出在发送表单数据的react代码中。
当客户端向服务器发送了不完整的请求时,服务器会发送'408‘错误。
这个问题可以追溯到以下语句块
'httpRequest.open("POST",“本地主机:8080/sa/searchData”,true);...
此代码块正在打开与服务器的连接,但从未完成发送请求。
这会导致服务器在等待来自客户端的完整请求时超时,并最终发送408错误。
如何解决这个问题?
在.open()之后添加一个.send()方法来完成HTTP请求的发送。
一个工作代码片段的示例:
httpRequest.open('POST', "localhost:8080/sa/searchData", true)
// add headers and other parameters
// Send the request
httpRequest.send()更多信息:
https://stackoverflow.com/questions/60380282
复制相似问题