I have a page setup on my webserver with an 'email address' box and a submit button. I have it so when it is submitted, it sends a post request to check if it exists in my database. I have been using Go to try and send this POST request. However, I need to send the request body as the following:
demo_mail=<email>
I haven't found anything remotely useful online, only posts asking how to send the data with JSON rather than a string. I currently have the following code which runs but fails to send the POST request with the post data above.
req, err := http.NewRequest("POST", "<MY PAGE>", ioutil.NopCloser(bytes.NewBufferString("demo_mail=" + email)))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
color.Red("Error.")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if strings.Contains(string(body), "Success") {
fmt.Println("Email exists")
} else {
fmt.Println("Fail")
}
Any help is appreciated.