Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c.Bind is not working when the request is made via html form but works from postman #87

Closed
shyamchandranmec opened this issue Nov 26, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@shyamchandranmec
Copy link

shyamchandranmec commented Nov 26, 2023

Here is the HTML form

<form method="POST" action="/login">
    <input type = "text" name = "username" placeholder="username"/>
    <input type  = "password" name="password" placeholder="password"/>
    <input type = "submit" value="Login"/>
</form>

The header value of content type is application/x-www-form-urlencoded

//Backend code
package models
type Login struct {
	Username string `json:"username"`
	Password string `json:"password"`
}
package handlers
func LogiReq(c *gofr.Context) (interface{}, error) {
	c.Logger.Info("Login request ")
	var login models.Login
	err := c.Bind(&login)
	if err != nil {
		c.Logger.Errorf("Error in binding request body %w ", err)
	}
	c.Logger.Info("Login request for username ", login.Username)
	return login.Username, nil
}

The above code throws error on c.Bind.
*ERRO [14:06:48] Error in binding request body %!w(json.SyntaxError=&{invalid character 'u' looking for beginning of value 1}) StackTrace: goroutine 82 [running]:

However, it works fine when the request is sent from PostMan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants