Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

<template>
    <div>
        <input type="button" @click="join(8058865)" value="8058865" name="mr_id">
        <input type="button" @click="join(8058866)" value="8058866" name="mr_id">
        <input type="button" @click="join(8058867)" value="8058867" name="mr_id">
    div>
template>

<script>
import '../rawsdk/zjsdk2.js'
import '../js/demo_config.js'
import '../js/demo_public.js'
import '../js/demo_enterMeeting.js'
import append_dev_header from '../rawsdk/dev_header'//必要
import md5 from '../js/md5'
export default {
    methods: {
        //新建视频页面
        join(id) {
            var route = this.$router.resolve({
                name: 'video',
            })
            sessionStorage.setItem("id", id);
            window.open(route.href, '_blank')
        },

    },
    data() {
        return {
            cert_code: '',
            date_time: ''
        }
    },
    mounted() {
        const xhr = new XMLHttpRequest()
        //获取验证码
        xhr.open('get', '/api/rest/v1/app1/manager/sessions/verify-code/', true);

        xhr.send();  //发送请求

        xhr.onreadystatechange = function () {
            console.log(xhr.readyState)
            console.log(xhr.status)
            if (xhr.readyState == 4 && xhr.status == 200) {
                console.log('responseText:' + xhr.responseText);
                console.log('responseXML:' + xhr.responseXML)
                var json = JSON.parse(xhr.responseText);
                this.cert_code = json.cert_code
                this.date_time = json.date_time
                //登录
                xhr.open('post', '/api/rest/v1/app1/manager/sessions/login_req/', true);
                var fd = new FormData()
                fd.append('cmdid', 'login_req')
                fd.append('login_id', 'hmy@ecflow.com.cn')//加了这一句
                fd.append('login_pwd', md5('123456'))//加了这一句
                fd.append('login_type', 1)//加了这一句
                fd.append('cert_code', this.cert_code)//加了这一句
                fd.append('date_time', this.date_time)//加了这一句
                xhr.send(fd);  //发送请求
                // console.log('this.code:' + this.cert_code)
                // console.log('this.time:' + this.date_time)
                // xhr.onreadystatechange = function () {
                //     console.log(xhr.readyState)
                //     console.log(xhr.status)
                //     if (xhr.readyState == 4 && xhr.status == 200) {
                //         console.log('responseText:' + xhr.responseText);
                //         console.log('responseXML:' + xhr.responseXML)
                //         var json = JSON.parse(xhr.responseText);
                //     } else {
                //         console.log('statusText:' + xhr.statusText);
                //     }
                // };
            } else {
                console.log('statusText:' + xhr.statusText);
            }
        };
    },

}
script>

<style scoped>
div {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

input {
    width: 100px;
    height: 100px;
    border-radius: 10px;
    background-color: lightblue;
    color: blue;
    font-weight: bolder;
    font-size: larger;
    border-color: lightyellow;
}
style>

在第二个send(最后一个)处报错,有时候一开始是能成功的,然后一旦报错就会一直有,隔一段时间可能又好了
而且一开始是这个错误,刷新之后就会变成POST http://127.0.0.1:5173/api/rest/v1/app1/manager/sessions/login_req/ 405 (Method Not Allowed)
然后就一直是POST http://127.0.0.1:5173/api/rest/v1/app1/manager/sessions/login_req/ 405 (Method Not Allowed)了
希望能让其稳定有效

重新创建一个请求试试看

img

https://www.656463.com/wenda/ASPNetCORScwwfjzzyfwqxyztw405ffb_228

看报错是后台的接口不支持。但你有调用成功过,这种情况下可以先用一些工具测试一下后端的稳定性,比如用postman等接口工具,按照你的时间间隔,跑几次试一下,如果证明后端确实存在不稳定性,可以找后台的同学调试,毕竟你开发都存在这种问题,上线了肯定问题更多,建议还是改好再上线。

          const xhr1 = new XMLHttpRequest()
 xhr1.open('post', '/api/rest/v1/app1/manager/sessions/login_req/', true);
                var fd = new FormData()
                fd.append('cmdid', 'login_req')
                fd.append('login_id', 'hmy@ecflow.com.cn')//加了这一句
                fd.append('login_pwd', md5('123456'))//加了这一句
                fd.append('login_type', 1)//加了这一句
                fd.append('cert_code', this.cert_code)//加了这一句
                fd.append('date_time', this.date_time)//加了这一句
                xhr1.send(fd);

重新创建一个请求

先打印一下fd数据 或者查看network里面请求接口参数是否正确

xhr的post请求,需要设置请求头,你设置完之后看看成不成,不成的话再把fd打出来看看,参数格式要符合要求

var xhr = new XMLHttpRequest;
//1. 设置请求行 post请求的参数列表在请求体中
xhr.open("post", url);
 
//2. 设置请求头, post请求必须设置content-type,不然后端无法获取到数据
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
 
//3. 设置请求体
xhr.send("name=hucc&age=18");