golang request with cookie

    url := "http://127.0.0.1:8998"
    req, err := http.NewRequest("POST", url, nil)
    if err != nil {
        log.Error(err)
    }

    cookie := http.Cookie{Name: "cookie_name", Value: "cookie_value"}
    req.AddCookie(&cookie)
    var client = &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        log.Error(err)
    }
    defer resp.Body.Close()

    ret, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        return
    }
  • Vikram 2017-05-25 13:26:42

    Very good and to the point. Thanks