简体   繁体   中英

POST contents of a form to rest api

I have made a html user login form:

<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. 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. 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?

First fix your HTML. Then with the following no javascript is necessary:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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