javascript - React 在 React 中找不到 url
问题描述
您好正在表单提交上执行 LoginValidation。我在提交时调用方法 validatelogin。方法如下,
ValidateLogin(e)
{
if(this.state.formValid)
{
let userid = this.state.userId;
let password = this.state.password;
let url = "http://localhost:3727/api/Login/ValidateUser";
fetch(url, {
method: "POST",
mode: 'no-cors',
body : "userid=" + userid +"&password=" + password
}).then((response) => console.Log(respose));
}
};
使用代码执行它显示 url not found return 404 但邮递员正在使用相同的 url。此网址仅接受发布请求。没有得到任何线索是怎么回事。我们是否必须在 React 中注册一些端点才能进行 api 调用?
解决方案
试试这个。它正在处理我的情况。请确保客户端和服务在同一个域和同一个端口中(cors 不是问题)。
ValidateLogin(e)
{
if(this.state.formValid)
{
let userid = this.state.userId;
let password = this.state.password;
let url = "http://localhost:3727/api/Login/ValidateUser";
fetch(url, {
method: "POST",
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded', // <-- Specifying the Content-Type
}),
mode: 'no-cors',
body : "userid=" + userid +"&password=" + password
}).then((response) => console.Log(respose));
}
};
推荐阅读
- jenkins - 如何在 Jenkins 管道中运行远程库函数时修复“java.io.NotSerializableException”
- javascript - 如何在剑道网格上分页或更改选项卡时保持选择复选框状态
- unit-testing - Java - 使用 Matchers 对 void 方法进行单元测试
- javascript - 对象数组是否存在已知问题?例如,当给 a[0].name 赋值时,元素 a[1].name 也得到相同的值
- c# - 导航到下一页时丢失模型数据
- python - 关于如何添加颜色的散点图?
- python - pyuic5.exe 不输出任何内容并清除输入文件
- c# - 写入 Input 键的字符串名称
- dart - 我们如何在flutter Text或RichText中使用上标和下标文本
- mysql - 用于处理员工能力的 SQL 架构设计