英文:
NTLM and Golang
问题
我最近学习了Go语言,并且正在尝试使用net/http
库进行实验。我一直在尝试使用http.SetBasicAuth
函数进行站点身份验证,但似乎从未成功。使用cURL
时可以正常工作,但在Go中不行。我知道这与NTLM
有关,但我不知道如何解决这个问题。
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)
返回的body一直是站点的401页面。
英文:
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.
答案1
得分: 6
NTLM身份验证和基本身份验证不同。NTLM是一个比仅在标头中使用用户:密码字符串更复杂的协议。
如果您想要从Golang代码发出身份验证请求,您应该使用现有的库之一,例如:go-ntlmssp。
您还可以在此处了解有关NTLM协议本身的更多信息。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论