简体   繁体   English

我如何修复 PUT 405(不允许的方法)错误

[英]How do i fix PUT 405 (Method Not Allowed) error

im trying to make a website where users can upload things to my server but when i try it it says我正在尝试制作一个网站,用户可以在其中将内容上传到我的服务器,但是当我尝试时它说

"PUT 405 (Method Not Allowed)" here is my code “PUT 405(不允许的方法)”这是我的代码

<html>
<body>
    <h1>Upload</h1>
<input id="file" type="file">

<br>
<button onclick="upload()">Upload</button>
<hr>
</body>
<script>
function upload() {
    let data = document.getElementById("file").files[0];
    let entry = document.getElementById("file").files[0];
    console.log('doupload',entry,data)
    fetch('/files/' + encodeURIComponent(entry.name), {method:'PUT',body:data});
console.log(data)
console.log(entry)
}
</script>
</html>

BTW i use xampp on windows and windows file permitions are NOT read only顺便说一句,我在 Windows 上使用 xampp 并且 Windows 文件许可不是只读的

Web servers do not generally come with built-in implementations of PUT. Web 服务器通常不附带 PUT 的内置实现。

Nobody wants any drive-by client to be able to write to their server (especially if they pick an existing URL and overwrite files that are already there!).没有人希望任何路过的客户端能够写入他们的服务器(特别是如果他们选择一个现有的 URL 并覆盖已经存在的文件!)。

In order to support PUT you need to write server-side code to handle the request (and unless you are in a very unusual position you will need to include authentication and authorisation checks as part of that code).为了支持 PUT,您需要编写服务器端代码来处理请求(除非您处于非常不寻常的位置,否则您需要将身份验证和授权检查作为该代码的一部分)。

Once you've written server side code to handle the request you can tell Apache HTTPD to allow them with mod_allowmethods .一旦您编写了服务器端代码来处理请求,您就可以告诉 Apache HTTPD 使用mod_allowmethods允许它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM