Golang web scraper NTLM authentication

不想你离开。 提交于 2019-12-13 16:08:59

问题


A Golang web scraper needs to extract information from a webpage that is NTLM-authenticated.

Having a valid username & password, how can the web scraper perform the NTLM 4-way handshake with the server in order to gain access to the protected webpage behind?

url, username, password := "http://www.some-website.com", "admin", "12345"

client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Authorization", "NTLM")
res, _ := client.Do(req)

回答1:


You can use a package like Azure/go-ntlmssp to authenticate before you start scraping.

url, username, password := "http://www.some-website.com", "admin", "12345"

client := &http.Client{
    Transport: ntlmssp.Negotiator{
        RoundTripper:&http.Transport{},
    },
}

req, _ := http.NewRequest("GET", url, nil)
req.SetBasicAuth(username, password)

res, _ := client.Do(req)


来源:https://stackoverflow.com/questions/40488583/golang-web-scraper-ntlm-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!