Go HTTP Post and use Cookies

前端 未结 4 983
梦毁少年i
梦毁少年i 2020-12-01 04:07

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 a

4条回答
  •  庸人自扰
    2020-12-01 04:18

    Go 1.1 introduced a cookie jar implementation net/http/cookiejar.

    import (
        "net/http"
        "net/http/cookiejar"
    )
    
    jar, err := cookiejar.New(nil)
    if err != nil { // error handling }
    
    client := &http.Client{
        Jar: jar,
    }
    

提交回复
热议问题