Skip to content

Instantly share code, notes, and snippets.

@voldyman
Created May 2, 2014 18:12
Show Gist options
  • Save voldyman/838cf67ed9a0da51ae57 to your computer and use it in GitHub Desktop.
Save voldyman/838cf67ed9a0da51ae57 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"net/http"
"net/url"
"io"
"io/ioutil"
"os"
)
type response struct {
Token string `json: token`
}
func main() {
email := ""
password := ""
resp, err := http.Post("https://www.irccloud.com/chat/auth-formtoken", "", nil)
if err != nil {
panic(err)
}
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var data response
json.Unmarshal(respBody, &data)
println(data.Token)
request := &http.Request{}
request.URL, _ = url.Parse("https://www.irccloud.com/chat/login")
request.Method = "POST"
request.PostForm = url.Values{}
request.PostForm.Add("email", email)
request.PostForm.Add("password", password)
request.PostForm.Add("token", data.Token)
headers := make(http.Header)
headers.Add("x-auth-formtoken", data.Token)
request.Header = headers
request.Header.Write(os.Stdout)
client := &http.Client{}
resp, err = client.Do(request)
if err != nil {
panic(err)
}
io.Copy(os.Stdout, resp.Body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment