【问题标题】:xmlhttprequest POST 405 - Method NOT ALLOWEDxmlhttprequest POST 405 - 不允许的方法
【发布时间】:2016-12-04 03:21:32
【问题描述】:

我有一个让我发疯的问题,因为我无法解决它。我想用我的应用程序将一些文件上传到服务器 IIS。

我的 HTML 代码是:

<input id="files" type="file" />

当我检测到添加了新文件时,就在控制器中使用 XMLHttpRequest:

document.getElementById('files').addEventListener('change', function (e) {
        var file = this.files[0];
        var xhr = new XMLHttpRequest();
        (xhr.upload || xhr).addEventListener('progress', function (e) {
            var done = e.position || e.loaded
            var total = e.totalSize || e.total;
            console.log('xhr progress: ' + Math.round(done / total * 100) + '%');
        });

        xhr.open('POST', 'http://10.0.19.25:80/CG/files', true);

        xhr.addEventListener('load', function (e) {
            console.log('xhr upload complete', e, this.responseText);
        });

       xhr.send(file);
    });

当我在 Chrome、Firefox 或 IE 上启动我的应用程序时,我收到此错误:

POST http://10.0.19.25/CG/files 405 (Method Not Allowed)

enter image description here

提前致谢!

【问题讨论】:

    标签: methods xmlhttprequest


    【解决方案1】:

    我遇到了同样的错误,问题是我尝试访问的方法不存在,所以我尝试使用 POST 但在该 URL 中的服务器上应该是 PUT。

    查看服务器日志可能会有所帮助!

    【讨论】:

      【解决方案2】:

      我认为您需要阅读更多有关内容类型的信息。我有同样的问题,我在服务器上发送 json 数据,我只是将 Content-type 更改为 application / json; charset = UTF-8,有帮助,默认是 text/html;字符集 = utf-8。

      【讨论】:

        猜你喜欢
        • 2021-04-05
        • 2014-05-23
        • 2018-12-20
        • 2015-11-16
        • 2016-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-01
        相关资源
        最近更新 更多