Reputation: 31
I have recently learnt Go and I am experimenting with the net/http
library. I have been trying to authenticate into a site using the http.SetBasicAuth
function but it never seems to work. It works fine with cURL
but not with Go. I know this has something to do with NTLM
but I don't know how to fix the problem
cURL:
curl -v "http://server_that_im_trying_to_auth_with" --ntlm -u user:pass
Go:
req, _ := http.NewRequest("GET", "url", nil)
req.SetBasicAuth(user, pass)
resp, _ := http.DefaultClient.Do(req)
body, _ := ioutil.ReadAll(resp.Body)
The body keeps on returning the sites 401 Page.
Upvotes: 1
Views: 3966
Reputation: 2087
NTLM Authentication and Basic Authentication are not the same. NTLM is a protocol which is more complicated than just user:password string in header.
If you want to make a request from Golang code to authenticate you should use one of existing libraries, like: go-ntlmssp
Also you can read more about NTLM protocol itself here
Upvotes: 6