2018-05-23 08:49
浏览 112


How do I send the post in GoLang?

I have the following code in ruby, now I need to transfer into Golang.

http ='', 443)
http.use_ssl = true

path = '/abc/login'
data = 'data[Account][username]=myusername&data[Account][passwd]=mypassword'
resp, _ =, data)

This way, I can get the cookie after login request.

But I don't know how to send a post request in Go.

I've written the following code.

path := ""
data := strings.NewReader("data[Account][username]=myusername&data[Account][passwd]=mypassword")
resp, err := http.Post(path, "text/html; charset=UTF-8", data)

It seems not correct, because I didn't find a way to get cookie.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubi9999 2018-05-23 09:02

    To get the cookies you should call the Cookies() method that's part of http.Response, try this:

    for _, cookie := range resp.Cookies() {
      fmt.Println("Found a cookie named:", cookie.Name)

    See the Cookie fields here.

    解决 无用
    打赏 举报

相关推荐 更多相似问题