javascript - 如何使用 POST 方法修复 net::err_aborted 415?
问题描述
我正在尝试向我的后端发送 POST 请求,但我收到“net::ERR_ABORTED 415”错误。我在后端使用 Spring,在前端使用 React。我已经禁用了 CORS,因为我遇到了问题。这是反应代码:
const sendInfos = (e) => {
e.preventDefault()
fetch('http://localhost:9090/Register', {
mode: 'no-cors',
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: name,
password: password,
email: email
})
});
}
这是Java Spring代码:
@RestController
public class RegistrationController {
@Autowired
private UserDao userDao;
@Autowired
BCryptPasswordEncoder encoder;
@PostMapping(value = "/Register")
@ResponseStatus(code = HttpStatus.CREATED)
public void PlayerRegistration(@RequestBody UserCredentials userDto) throws UserAlreadyRegisteredException{
if(userDao.findByEmail(userDto.getEmail()) != null){
throw new UserAlreadyRegisteredException("This email is already registered on the system.");
}
User user = new User();
user.setName(userDto.getName());
user.setPassword(encoder.encode(userDto.getPassword()));
user.setEmail(userDto.getEmail());
user.setElo(1200);
userDao.save(user);
}
}
我已经和我最好的朋友“google”一起寻找答案,但我找到的所有答案都不起作用。有谁知道如何修理它?
解决方案
推荐阅读
- reactjs - 如何将 react-select 组件的高度设置为 100%?
- ruby-on-rails - 带导轨的 Vue。如何在 VUE 代码中使用模型
- javascript - Ant Design Form.getFieldsError 总是返回空错误
- c# - Unity WaitForSeconds 功能无法正常工作
- pine-script - 将价格保存在数组中以便稍后检索
- pyspark - spark struct streaming writeStream 输出无数据但无错误
- node.js - 为什么我不能在从快速路由调用的异步函数中使用 for 循环进行迭代?
- c# - 在适用于 iOS 的 Safari 上的 Blazor WASM 中信任自签名证书
- mysql - 可执行文件未连接到数据库 Mariadb 或 MySql
- javascript - Vimeo Player SDK - 自定义 PIP / 一个视频在两个地方同步播放 - 无需两次加载相同的数据