I'm trying to use Go to log into a website and store the cookies for later use.
Could you give example code for posting a form, storing the cookies, and accessing another page using the cookies?
I think I might need to make a Client to store the cookies, by studying http://gotour.golang.org/src/pkg/net/http/client.go
package main
import ("net/http"
"log"
"net/url"
)
func Login(user, password string) string {
postUrl := "http://www.pge.com/eum/login"
// Set up Login
values := make(url.Values)
values.Set("user", user)
values.Set("password", password)
// Submit form
resp, err := http.PostForm(postUrl, values)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
// How do I store cookies?
return "Hello"
}
func ViewBill(url string, cookies) string {
//What do I put here?
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…