[Solved] Golang “Log in to the site and download the xls file”? [closed]


I do not know VBA, but it seems to me what you are doing a HTTP POST with the credentials, and then you are doing a HTTP GET to obtain the file you are looking for. I guess the class you are using keeps the cookies from request to request and that is how the authentication works.

Assuming that, in Go you would use the library https://golang.org/pkg/net/http/cookiejar/ to keep the cookies and https://golang.org/pkg/net/http/ to do the actual requests.

You pass each time the same cookie jar.

Something along these lines (not exact or checked):

package main

import (
    "net/http"
    "net/http/cookiejar"
)

func main() {
    cookieJar, _ := cookiejar.New(nil)

    client := &http.Client{
        Jar: cookieJar,
    }

    resp, err := http.PostForm("http://example.com/loginform",
        url.Values{"login": {"sdiscor"}, "password": {"sdiscor"}})
    resp, err := client.Get("http://example.com/")
}

solved Golang “Log in to the site and download the xls file”? [closed]