【发布时间】:2020-07-08 19:47:29
【问题描述】:
我有一个 dotnet core 3.1 API 和一个 React 应用程序。
当我使用 React 应用程序执行 DELETE 请求时,我得到了一个不允许的方法 (405)。
DelBiere.tsx:45 DELETE https://localhost:44339/api/v1/biere 405
还有
4:1 Uncaught (in promise) SyntaxError: Unexpected token S in JSON at position 0.
但是当我使用 Postman 时,一切正常。
此外,GET 和 POST 请求适用于 React 应用。
我没有在 IIS 上安装 WEBDAV。
我有一个这样的 web.config 文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="AspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
我的反应处理函数如下所示:
handleSubmit(event: any) {
fetch('https://localhost:44339/api/v1/biere', {
method: 'DELETE',
headers : {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body:JSON.stringify(this.id)
})
.then((res) => console.log(res.json(), "res"))
.then((data) => console.log(data, "data"))
.catch((err)=>console.log(err, "err"));
event.preventDefault();
}
感谢您的帮助!
【问题讨论】:
标签: reactjs asp.net-core iis