繁体   English   中英

Chrome 在请求中抛出缺少的参数。 发送用户名、电子邮件、密码错误

[英]Chrome throwing Missing parameters in request. Send user_name, email, password error

我正在尝试使用 API 对用户进行身份验证。 登录 API 工作正常。 如果一个人没有注册,它会打印消息以先注册。 但是注册功能不起作用。 我在点击注册 API 时收到响应代码 400。

它显示以下消息:

Missing parameters in request. Send user_name, email, password

我无法理解我哪里出错了。 理想情况下,它应该点击 API 并创建一个新用户,然后应该重定向到下一页。

这是我的注册功能代码

$(".form-item.sign-up .btn").click(
  async () => {
    get_email = document.getElementById("email_box2").value;
    get_password = document.getElementById("password2").value;
    get_username = document.getElementById("username").value;
    console.log(get_email, get_password, get_username);
    const response = await fetch('http://127.0.0.1:81/traveliobot/api/v1/auth/register', {
      method: 'POST',
      mode: 'cors',
      cache: 'no-cache',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        'email': get_email,
        'password': get_password,
        'username': get_username
      }) // string or object

    });
    const myJson = await response.json(); //extract JSON from the http response
    response_code = myJson.responseCode
    console.log(response_code)
    if (response_code == '0') {
      user_id = myJson.user_id;
      console.log(user_id)
      linkLocation = 'chat_index.html';
      window.sessionStorage.setItem("user_id", user_id);
      $("body").fadeOut(1500, redirect_page)
    } else {
      console.log(myJson.responseDesc)
    }
  }
);

function redirect_page() {
  window.location = linkLocation;
  widn
}

登录功能:

$(".form-item.log-in .btn").click(
  async () => {
    get_email = document.getElementById("email_box1").value;
    get_password = document.getElementById("password1").value;
    const response = await fetch('http://127.0.0.1:81/traveliobot/api/v1/auth/login', {
      method: 'POST',
      mode: 'cors',
      cache: 'no-cache',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        'email': get_email,
        'password': get_password
      }) // string or object

    });
    const myJson = await response.json(); //extract JSON from the http response
    response_code = myJson.responseCode
    console.log(response_code)
    if (response_code == '0') {
      user_id = myJson.user_id;
      console.log(user_id)
      linkLocation = 'chatbot_index.html';
      window.sessionStorage.setItem("user_id", user_id);
      $("body").fadeOut(1500, redirect_page)
    } else {
      console.log(myJson.responseDesc)
    }
  }
);

function redirect_page() {
  window.location = linkLocation;
  widn
}

html文件:

<div class="container-form">
                <div class="form-item log-in">
                    <div class="table">
                        <div class="table-cell">
                            <input name="Username" placeholder="Email" type="text" id="email_box1" /><input name="Password"
                                placeholder="Password" type="password" id="password1" />
                            <div class="btn">
                                Log in
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-item sign-up">
                    <div class="table">
                        <div class="table-cell">
                            <input name="email" placeholder="Email" type="text" id="email_box2" />
                            <input name="Username" placeholder="Username"type="text" id="username" />
                            <input name="Password" placeholder="Password" type="Password" id="password2" />
                            <div class="btn">
                                Sign up
                            </div>
                        </div>
                    </div>
                </div>
            </div>

任何帮助,将不胜感激。 提前致谢。

在 register API 调用的 JSON 负载中,您使用的是username而不是user_name

暂无
暂无

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

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