简体   繁体   English

POST 表单内容以休息 api

[英]POST contents of a form to rest api

I have made a html user login form:我制作了一个 html 用户登录表单:

<html >
<head>

<title>User Login</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/signin.css">
</head>

<body>
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<input class="form-control" type="text" autofocus="" required="" placeholder="Email address">
<input class="form-control" type="password" required="" placeholder="Password">
<label class="checkbox">

</label>
<a href= "" <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button></a>
</form>
</div>
</body>
</html>

I now need to send the contents of the form, ie the username and password, to a rest api for authentication using the http POST command.我现在需要使用 http POST 命令将表单的内容(即用户名和密码)发送到 rest api 以进行身份​​验证。 I have no idea where to start with this and am having trouble finding a tutorial which assumes absolutely no knowledge of rest APIs and http commands.我不知道从哪里开始,并且无法找到一个教程,该教程假设完全不了解 rest API 和 http 命令。 I'm extremely new to web development, can anyone point me in the direction of a good tutorial, or show me an example of what the javascript (I presume) might look like?我对 Web 开发非常陌生,任何人都可以向我指出一个好的教程的方向,或者向我展示 javascript(我认为)可能是什么样子的示例?

First fix your HTML.首先修复您的 HTML。 Then with the following no javascript is necessary:然后使用以下不需要 javascript:

<form class="form-signin" method="POST" action="URL_OF_REST">
  <h2 class="form-signin-heading">Please sign in</h2>
  <input class="form-control" type="text" required name="email" placeholder="Email address">
  <input class="form-control" type="password" required name="password" placeholder="Password">
  <label class="checkbox"></label>
  <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>

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

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