I have a login form with some html that users fill in:
<form method="post" enctype="multipart/form-data">
<div class="form"><input name="username"> </div>
<div class="form">
<button class="btn btn-primary btn-block" type="submit">Login</button>
I would like to test that the username is being received correctly. I am able to send a multipart form however this is contained within the body of the request not as a postform.
form := url.Values{}
form.Set("username", "Bob")
// Create request
req, _ := http.NewRequest("POST", "/login", strings.NewReader(form.Encode())) // sends as multipart form in request body
req.Header.Set("Content-Type", "application/www-form-urlencoded")
testRouter.ServeHTTP(rr, req)
How do I make a request with the form data attached as a Postform so that I can extract it c.Postform("username")
from the backend as if submitted via the browser?
Aucun commentaire:
Enregistrer un commentaire